logo       

Possible FAQ answer (Re: Multiple Test Cases): msg#00188

java.junit.user

Subject: Possible FAQ answer (Re: Multiple Test Cases)

> Hi,
> I am new to JUnit and need some clarification.

Welcome.

> 1.Do we need to create a Test-case class for every
> class we need to test.

No. It is a convention to start with one TestCase class per class under test,
but it is not necessary.

TestCase classes only provide a way to organize tests, nothing more.
Generally you will start with one TestCase class per class under test, but
then you may find that a small group of tests belong together with their own
common test fixture.[1] In this case, you may move those tests to a new
TestCase object. This is a simple object-oriented refactoring: separating
responsibilities of an object that does too much.

Another point to consider is that the TestSuite is the smallest execution
unit in JUnit: you cannot execute anything smaller than a TestSuite at one
time without changing source code. In this case, you probably do not want to
put tests in the same TestCase class unless they somehow "belong together".
If you have two groups of tests that you think you'd like to execute
separately from one another, it is wise to place them in separate TestCase
classes.

[1] A test fixture is a common set of test data and collaborating objects
shared by many tests. Generally they are implemented as instance variables in
the TestCase class.

> 2.Is there a way to test multiple classes.

Absolutely, but unless you describe a specific problem this is a difficult
question to answer.

--
J. B. Rainsberger,
President, Diaspar Software Services
Let's write software that people understand.
http://www.diasparsoftware.com/
telephone: +1 416 791-8603



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise