• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Should I use TestSuite in Junit 4?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Tp-Jonny Andersson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
author & internet detective
Posts: 41936
910
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Tp-Jonny Andersson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic