How do I define Junit Test Case without using @Test annotation

java, junit

Solution

You can use `JUnit 3`

import junit.framework.TestCase; 

public class DummyTestA extends TestCase {
    public void testSum() {
        int a = 5;
        int b = 10;
        int result = a + b;
        assertEquals(15, result);
    } 
}

But generally you should choose the annotation path, unless compatibility with `JUnit 3` (and/or a Java version earlier than Java 5) is needed for several reasons:

- The `@Test` annotation is more explicit and is easier to support in tools (for example it's easy to search for all tests this way)

- Multiple methods can be annotated with `@Before/@BeforeClass` and `@After/@AfterClass` providing more flexibility

- Integrated support for testing for expected exceptions using `expected=`

- Integrated support of the `@Ignored annotation`

- new features of `JUnit 4`: rules, parametrized tests, ...

see also JUnit website

Problem

I need to do Junit Test Case without using `@Test` annotation. It is working fine if I use `@Test` annotation. I would like to go for automation testing to perform Junit Testing as a bulk. Can you please give me some sample program to do that ? Note: I have tried Test Suite so please don't give any examples regarding the Test Suite.

Original source