4 Replies Latest reply: Nov 18, 2008 4:40 AM by 843785 RSS

    JUnit Test Classes

    843785
      Hello,

      I am generating file using java class.
      Now for this class I want write ont TestClass using JUnit how I will write such class?
      I want to know what will be my expected values for assertEquals() if i go for this??

      Thanks & Regards,
      Kate
        • 1. Re: JUnit Test Classes
          Alan.M
          Kasturi ,

          As per assertEquals("you message", expectedValue, actualValue)

          If you have a class Foo and there is a method called getSum(int i, int j), this method adds two interger to get their sum
          now

          in your test class you want to test the method above
          public void testGetSum() {
            Foo foo = new Foo();
           //int sum = foo.getSum(2,2); // you know that 2+2 = 4
            assertEquals("Sum of two are not equals", 4, foo.getSum(2,2));
          
          
          }
          Hope this could help

          Regards,
          Alan Mehio
          London,UK
          • 2. Re: JUnit Test Classes
            843785
            Thanks Alan Mehio,

            but my problem is, my class has method wich will generate one test file there is no other process takes place.
            And I want to write Test Class for such method ho can I do that?
            in this what will be my expected and actual output for the same??
            • 3. Re: JUnit Test Classes
              800583
              Kasturi wrote:
              Thanks Alan Mehio,

              but my problem is, my class has method wich will generate one test file there is no other process takes place.
              And I want to write Test Class for such method ho can I do that?
              in this what will be my expected and actual output for the same??
              [Testing using JUnit|http://www.drjava.org/userdocs/junit.html]


              Hope this helps! covers all you need to know.
              • 4. Re: JUnit Test Classes
                843785
                assertTrue(generatedFile.exists()) ??