September 28, 2004ant, make and tests: same fightGroboclown and I have had an interesting exchange about suite() on his weblog. The idea of using JUnit ant tasks to work around the limitations of JUnit is sadly very common, to the point that nobody notices even more that this is a fundamental flaw in JUnit. In this particular example, you can use <batchtest> to invoke explicitly several Test classes (something you can't even do with the basic TestRunner!) and also to use ant's powerful wildcard matching. This is useful, but it has two limitations:
That's a lot of work when all you need is to tell your test framework to run a specific test method. Groboclown quotes a book on this topic: In Testing Objet-Oriented Software: Life Cycle Solutions, by Imran Bashir and Amrit L. Goel, they argue that the unit of test has moved from the function (in structured programming) to the class (in object-oriented programming). Using this argument, I'll claim that there's no need to get a lower granularity than at the test class level.I disagree. The class level still fails to capture three very important levels of granularity in testing:
You declare dependencies between targets and you can group these dependencies together, creating an acyclic graph of clusters representing your run sequence where some processes are run sequentially while others can be run in parallel. Tests are no different, and whenever you use a framework that doesn't give you this flexibility, you are making your life unnecessarily hard. Comments
Here is how to run an individual test case within a test class: public static void main(String args[]) { Then you can "java com.whatever.Test_Class" to run all test cases within the class. Or you can "java com.whatever.Test_Class testFunction" to run an individual function. IDEA allows you to run a specific test method, so that takes care of that! It's depressing though how many people are desperate to define new design principles just to justify the shortcomings of JUnit. Posted by: Hani Suleiman at September 28, 2004 05:23 PMWell said Hani. Surely there are only two cases of running tests: 1. In your IDE when writing code - see Hani's comment about IDEA's JUnit support. 2. As part of your continous integration build - where you will always run all the tests and the JUnit support in Ant is easily up to the task. I am failing to see why a new framework is required. Perhaps a small change in developer behaviour will suffice? Posted by: Ian at September 29, 2004 12:37 AMThe point of TestNG is certainly not to address this particular deficiency of JUnit, it's just one of the added benefits. I still think that having to recompile my code to run a different set of tests is a basic flaw, though. Configuring in Java? We can do better than that. Besides, you would be surprised by the number of Java developers who still don't use an IDE. You DON'T need to recompile to run a single test method. That's just the way that YOU write your JUnit tests. Yes, that's a basic flaw, but it's YOUR flaw, not JUnit's. Posted by: at October 15, 2004 07:35 AMPost a comment
|