I have not got a good chance to use unit tests in any real work yet but I strongly support the idea and have therefore now studied the some of the small documentation articles I can find at junit.org to understand how to use the JUnit 4 API for unittesting. But one thing have confused me when I compare JUnit 3.8 and Junit 4: Where does the TestSuite fit in for Junit 4? Do I use TestSuite the same way in JUnit 4 as in Junit 3.8? Or if not, how do I organize my test cases "the correct way" in JUnit 4?
Sorry if I ask stupid questions that have already been asked and answered : ) but I really want learn to use JUnit in a good way from the beginning. [ July 13, 2006: Message edited by: TP-Jonny Andersson ]
I've never really used TestSuites in JUnit 3 for organizing my tests. What I have used it for has been purely because of setting up infrastructure for running, say, integration or functional tests against a locally deployed application server. I.e. nothing that involves unit tests (beyond the tests using the same framework, JUnit, for getting the job done).
As such, I'd first like to ask, what is it that you really need -- why would you want to use a TestSuite, regardless of which version of JUnit you have? When we get to that piece of information, we might be able to figure out a solution...
As such, I'd first like to ask, what is it that you really need -- why would you want to use a TestSuite, regardless of which version of JUnit you have?
Well, I don�t know! I have not used unit testing in a real project yet. But in my view of the JUnit framework so far is TestSuite the way to collect a number of selected tests together to more convenient run all them every time. And as I understand should all the tests preferrably be run after every code change, or at least daily. Are there then better ways than TestSuite to collect TestCases into suites to run all of them every time?
They can find all *Test classes and run all the tests in them. Eclipse and most IDEs do this.
I am using eclipse myself and have recently begin to us the newest version, eclipse 3.2, but then do I have to run the tests class by class like applications with thier own main, did I thought. So I dived into eclipse run dialog for configuration of JUnit tests to be run and found the option "Run all the tests in the selected project, package or source folder". So yes, now I agree that I don�t need TestSuites any longer. This is even better than creating TestSuites.
But for a new practioner that takes his first look at JUnit and the documentation at their site junit.org is TestSuites the way that is mentioned on how to organize tests. So if they also had an little article like "How to organize tests" that points on the features that the IDEs offer would it probably make good. And there would probably more to say in connection to that topic any way.
Thanks for your answers! It is people like you that makes these forums as one of the absolutely best sites on the net for developers to discuss things!
Joined: Jan 23, 2002
In Eclipse, you can right-click the project, a source folder, a single package and select "Run As > Junit Test".
Also, outside of an IDE you should consider using a build tool like Ant or Maven, which have "build tasks" for easily running all JUnit tests in your project. Apache Ant, for example, lets you specify a set of JUnit classes to run using a combination of source directories and wildcard patterns.