0

I used JUnit 3 and when I wrote this code I got this error

AssertionFailedError : No test Found

import junit.framework.TestCase;
import junit.runner.*;

public class Teststd extends TestCase {
    Student s;

    public void setUp() {
        s = new Student("ASJFA");
    }

    public void TestEmail() {
        try {
            s.setEmail("KUKU");
            assertTrue(false);
        } catch (EmailIsInvalid ex) {
            assertTrue(true);
            System.out.println("Exception caught. Email is invalid");

        }
    }

    public void tearDown() {
    }
}
3
  • 1
    Don't you need the annotations? e.g. @Test Commented Jun 13, 2015 at 9:52
  • 1
    @Gosu: The @Test annotations are for JUnit 4, not JUnit 3. For JUnit 3 names of test methods should start with test (small caps). Commented Jun 13, 2015 at 12:27
  • @lolex: Switching to JUnit 4 may also be a good idea. A simple idiom for testing exceptions in JUnit 4 would be @Test(expected=EmailIsInvalid.class), allowing you to get rid of the try-catch. Commented Jun 13, 2015 at 12:31

1 Answer 1

6

Your test method should start with a lowercase t. It should be public void testEmail(). Then it will be picked up by JUnit.

Not the answer you're looking for? Browse other questions tagged or ask your own question.