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 compo开发者_JAVA技巧site 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 :)
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.
精彩评论