aspose file tools*
The moose likes Testing and the fly likes Should I use TestSuite in Junit 4? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "Should I use TestSuite in Junit 4?" Watch "Should I use TestSuite in Junit 4?" New topic
Author

Should I use TestSuite in Junit 4?

Tp-Jonny Andersson
Greenhorn

Joined: Jul 13, 2006
Posts: 3
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 ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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...


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Tp-Jonny Andersson
Greenhorn

Joined: Jul 13, 2006
Posts: 3
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?

Thanks!
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Originally posted by TP-Jonny Andersson:
Are there then better ways than TestSuite to collect TestCases into suites to run all of them every time?

Yes. Most test runners use Reflection to find the tests. They can find all *Test classes and run all the tests in them. Eclipse and most IDEs do this. So does Ant's test runner.

Manually editing a TestSuite file works fine for just learning. But it's easy to forget to add a new test to the suite.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tp-Jonny Andersson
Greenhorn

Joined: Jul 13, 2006
Posts: 3
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!
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Should I use TestSuite in Junit 4?