0

I'm trying to use Junit at office (JVM 1.4): I wrote a lot of class extending TestCase but I didn't write any class extending TestSuite. The problem is that I don't understand very well what a TestSuite have to testing:

  • the public contract of a package(all the public method of all the public class of a package).
    Example:

    public class TestPackageAAA extends TestSuite{  
        //...  
        public void testSomething{  
            testSuite.add(new TestFirstClass()); 
            testSuite.add(new TestSecondClass());
        } 
        //... 
    }
    

    with FirstClass and SecondClass existing in the same package AAA.

  • the functional process, translated as a list of single class not integrated?

    public class TestProcessBBB extends TestSuite{  
        //...  
        public void testSomething{  
            testSuite.add(new TestFirstClass()); 
            testSuite.add(new TestSecondClass());
        } 
        //... 
    }
    

with FirstClass as first step of a user process named BBB (like a CRUD operation in webapp), the SecondClass as second step of the same process etc etc. (in this test, FirstClass and SecondClass don't communicate).

How do you organize your TestSuite? In the first way or second way? Or in another way?

EDIT: I'm wrong because I repeat the same name of class in the example, ergo it's confusing. This is the configuration of example:

src

|-->{package} **AAA**

       |--->{class}FirstClass
       |--->{class}SecondClass

|-->{package} **XYZ**

       |-->{class}ThirdClass

test

{package} **AAA**

       |--->{class}TestFirstClass extends TestCase
       |--->{class}TestSecondClass extends TestCase

|-->{package} **XYZ**

       |-->{class}TestThirdClass extends TestCase
  • first way:

TestSuiteAAA (placed in the root of testing directory) is a composite of all the TestCase in the package test.AAA

testSuite.add(new TestFirstClass()); 
testSuite.add(new TestSecondClass());
  • second way:

TestSuiteBBB (placed in the root of testing directory) is a composite of all the TestCase partecipating to execution of a functional process (example: sending a scheduled email for the admin of an e-commerce website). TestSuiteBBB call the methods of FirstClass and ThirdClass and each class don't call the methods of the other class.

testSuite.add(new TestFirstClass()); 
testSuite.add(new TestThirdClass());

JUnit allow me doing in both way (I coded them now in Eclipse and run): what do you prefer?

PS sorry for the formatting of structure of packages :)

Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
alepuzio
  • 1,382
  • 2
  • 28
  • 38

1 Answers1

0

Sorry, I don't know if this really answers your questions, but I find it very hard to understand your question.

Normaly you would have a own test directory in your build process. If you use Eclipse or Netbeans as your IDE, you would have one folder for source (src) and one folder for the tests. We normaly create the same package names in both the test and the src folder.

Most tool-chains pretty much force you to use this way of organizing your tests this way.

iuiz
  • 957
  • 1
  • 10
  • 23
  • Ok, this is true if you use an IDE (and this is the first situation). I don't have experience: do you say that it's the only way to put any TestCase in a TestSuite (in package view)? – alepuzio Nov 21 '10 at 15:22
  • No, it depends on your configuration. For example if you use ANT to build your project, you specify a JUnit target and in this target you specify your tests. Take a look at this article for further informations: http://ideoplex.com/id/25/ant-and-junit You can setup your programm however you want. But it would be better to have a folder called test. This also enables you to remove the tests before you deploy your project. – iuiz Nov 21 '10 at 16:02