2015-06-13 78 views
0

我使用JUnit 3中,当我写了这个代码,我得到这个错误JUnit测试错误没有测试发现

AssertionFailedError异常:没有检测发现

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() { 
    } 
} 
+1

你不需要注释吗?例如'@ Test' – Gosu

+1

@Gosu:'@ Test'注释是针对JUnit 4而不是JUnit 3.对于JUnit 3,测试方法的名称应该以'test'(小型大写)开头。 – avandeursen

+0

@avandeursen我明白了!感谢您指出:) – Gosu

回答

6

你的测试方法应该以启动小写t。它应该是public void testEmail()。然后它将被JUnit拾取。