Reputation: 2915
I encountered the weirdest issue with Eclipse Kepler, Service Release 1. I set up a class to implement some test cases by extending junit.framework.TestCase
, like so:
import junit.framework.TestCase;
public class PublicTests extends TestCase {
@Override
public void setUp(){
...
}
Then I added some public void
test case methods, all of the names of which started with the prefix test
. For example, testBasicAdd
. Then, I added another public void
test case method, named stressTestForAdd()
, and when I ran all the test cases, that particular one was not even recognized as a test case and therefore not run. I made sure that it was actually not recognized as a test case by deleting all other methods, thus creating an instance of TestCase
with stressTestForAdd
as its only test case, and when I re-ran the suite I received a neat AssertionError
stating that I hadn't authored any test cases in my file. When I added the prefix test
to my method, creating the unwieldy name testStressTestForAdd
, the test case was recognized.
I haven't encountered the need to have the test
prefix in a jUnit test case anywhere in the relevant literature, not even as a convention. Is this a bug of Eclipse, perhaps? Can anybody shed some light?
Upvotes: 1
Views: 626
Reputation: 11841
In early versions of JUnit e.g. JUnit 3, methods are executed as tests as long as the method name begins with test
e.g.
public void testGetName()
In JUnit 4, support for annotations was introduced, thus in JUnit 4, you may name your test method anything you desire as long as you annotate it with @Test
e.g.
@Test
public void getName()
Upvotes: 4