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() {
    }
}
Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
lolex
  • 65
  • 11
  • 1
    Don't you need the annotations? e.g. `@Test` – almightyGOSU Jun 13 '15 at 09: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). – avandeursen Jun 13 '15 at 12:27
  • @avandeursen I see! Thanks for pointing that out :) – almightyGOSU Jun 13 '15 at 12:29
  • @lolex: Switching to JUnit 4 may also be a good idea. A simple idiom for [testing exceptions](http://stackoverflow.com/questions/156503/how-do-you-assert-that-a-certain-exception-is-thrown-in-junit-4-tests) in JUnit 4 would be `@Test(expected=EmailIsInvalid.class)`, allowing you to get rid of the try-catch. – avandeursen Jun 13 '15 at 12:31

1 Answers1

6

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

Kai Sternad
  • 22,214
  • 7
  • 47
  • 42