I'm working with a legacy project that has:
I'm looking for the simplest way to run both types of tests separately with Ant.
I wonder if there's a way to have Ant automatically recognise these two categories based on the inheritance hierarchy:
StringUtilsTest extends TestCase // "pure unit test"
vs
ProductionDBTest extends AbstractTransactionalTesterBase // "integration test"
There's a hierarchy of abstract superclasses that integration tests are based on, but they all come down to some Spring test classes and ultimately AbstractSpringContextTests
which extends junit.framework.TestCase
.
In other words, can I distinguish, in Ant, tests that (indirectly) extend AbstractSpringContextTests
and tests that directly extend TestCase
? Or would I have to manually go through the tests and e.g. put them in separate Categories or TestSuites? (There are many tests so I wouldn't want to do that.)
Resolution: I tried Sean's (very promising) approach, but couldn't get it working (easily). So I ended up going through the tests semi-manually after all, annotating the pure ones (which was the smaller group) using a setup described in this SO question, and running them with Ant like this. (Note that writing a custom TestRunner is not necessary.)
JUnit test suites help to grouping and executing tests in bulk. Executing tests separately for all test classes is not desired in most cases. Test suites help in achieving this grouping. In JUnit, test suites can be created and executed with these annotations.
The reason behind this is to prevent ambiguity. Consider a case where class B extends class A and Class C and both class A and C have the same method display(). Now java compiler cannot decide, which display method it should inherit. To prevent such situation, multiple inheritances is not allowed in java.
class) This annotation is helpful whenever we want to test multiple classes at once. In this case we do not need to run each individual class for testing.
TestNG Groups allow you to perform groupings of different test methods. Grouping of test methods is required when you want to access the test methods of different classes.
The solution we used for categorizing our JUnit tests was using a custom annotation. You can then use a custom TestRunner with that which can be given a flag or argument as to which test types to run, or all of them.
Sorry, no example code but creating annotations and a TestRunner is pretty basic, give it a try!
The simple way is to name your test classes ending with the test type
Lets say we were testing dates.
DateTest.java (Quick normal tests)
DateSysTest.java (Long running )
Then in there were two targets one the quick unit tests has
<batchtest todir="your dir">
<!--Run unit tests for each class with suffix Test, unless it is SysTest or StressTest-->
<fileset dir="${src}/test"
includes="**/*Test.java"
excludes="**/*StressTest.java **/*SysTest.java" />
</batchtest>
You then create a few ant targets, one for quick tests one for sys tests and one do them all.. Something like that. That is to say if you can rename your test classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With