junit.framework.AssertionFailedError:在寄存器中找不到测试

时间:2012-04-10 22:03:24

标签: selenium junit selenium-rc

我在让这个测试用例工作时遇到了问题。谁能指出我正确的方向?我知道我做错了什么,我只是不知道是什么。

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)

我很难过。

4 个答案:

答案 0 :(得分:24)

您既不能扩展TestCase(或SeleniumTestCase),也不能使用JUnit注释(@Test)。 JUnit3和4的测试运行器是不同的,我的假设是当JUnit看到你扩展了TestCase时,它使用了旧的跑步者。

删除@Test注释,而是遵循命名测试的旧约定,前缀为“test”,这将解决它。

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

PS。我建议遵循更多标准的Java命名约定,例如驼峰外壳。

PPS。这是一个link,可以更详细地解释这一点。

答案 1 :(得分:2)

这意味着您没有在以下测试用例类中创建以test开头的方法名称当前正在运行的

答案 2 :(得分:1)

我能够在我的情况下解决此错误 - 即,使用<junit> Ant任务运行测试 - 指向1.7或更高版本的Ant。 Ant 1.7+尊重嵌套的<classpath>元素,其中我指向一个JUnit 4.x jar,正如CodeSpelunker所指出的那样理解@Test注释。 http://ant.apache.org/faq.html#delegating-classloader为我提供了一个时刻。

答案 3 :(得分:1)

我在 Android 版 Kotlin 中使用 mockk,但出现此错误。

我的类是这样声明的(由 Android Studio 自动生成):

class MyClassTest : TestCase() {

但删除 TestCase 修复了错误

class MyClassTest {