2012-04-10 67 views
3

我在使本測試案例正常工作時遇到問題。任何人都可以將我指向正確的方向嗎?我知道我做錯了什麼,我只是不知道。junit.framework.AssertionFailedError:在寄存器中找不到測試

import org.junit.*; 
import com.thoughtworks.selenium.*; 
import org.openqa.selenium.server.*; 

@SuppressWarnings("deprecation") 

public class register extends SeleneseTestCase { 

    Selenium selenium; 
    private SeleniumServer seleniumServer; 
    public static final String MAX_WAIT = "60000"; 
    public final String CRN = "12761"; 

    public void setUp() throws Exception { 
    RemoteControlConfiguration rc = new RemoteControlConfiguration(); 
    rc.setAvoidProxy(true); 
    rc.setSingleWindow(true); 
    rc.setReuseBrowserSessions(true); 

    seleniumServer = new SeleniumServer(rc); 
    selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://google.com/"); 
    seleniumServer.start(); 
    selenium.start(); 
    } 

    @Test 
    public void register_test() throws Exception { 
    //TESTS IN HERE 
    } 

    @After 
    public void tearDown() throws Exception { 
    selenium.stop(); 
    // Thread.sleep(500000); 
    } 
} 

而且,我發現了以下錯誤:

junit.framework.AssertionFailedError: No tests found in register 
at jumnit.framework.TestSuite$1.runTest(TestSuite.java:97) 

我難倒。

回答

24

您不能同時擴展TestCase(或SeleniumTestCase)和使用JUnit註釋(@Test)。 JUnit3和4的測試運行者是不同的,我的假設是當JUnit發現你已經擴展了TestCase時,它使用舊的跑步者。

刪除@Test註釋,而是按照舊慣例命名您的測試,前面加上「test」一詞,這將解決它。

public void testRegister() throws Exception { 
    //TESTS IN HERE 
} 

PS。我建議遵循更多的標準Java命名約定,如駱駝套。

PPS。這是一個link,更詳細地解釋了這一點。

1

在我的例子中,我能夠解決這個錯誤 - 也就是說,通過指向1.7或更高版本的Ant,運行帶有<junit> Ant任務的測試。 Ant 1.7+榮譽嵌套<classpath>元素,其中我指向一個JUnit 4.x jar,CodeSpelunker表示理解@Test註釋。 http://ant.apache.org/faq.html#delegating-classloader爲我提供了這個時刻。

2

這意味着您沒有在下面的測試用例類中創建方法名稱並以test開頭