4

I'm having a problem getting this test case to work. Can anyone point me in the right direction? I know I'm doing something wrong, I just don't know what.

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);
  }
}

And I'm getting the following errors:

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

I'm stumped.

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
Sathed
  • 836
  • 1
  • 11
  • 21

4 Answers4

31

You can't both extend TestCase (or SeleniumTestCase) and also use JUnit annotations (@Test). The test runners for JUnit3 and 4 are different, and my assumption is when JUnit sees that you've extended TestCase, it uses the old runner.

Remove the @Test annotation, and instead follow the old convention of naming your test with the word "test" prefixed, and that will fix it.

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

PS. I'd recommend following more standard Java naming conventions, such as camel casing.

PPS. Here's a link that explains this in more detail.

Community
  • 1
  • 1
Ryan Nelson
  • 4,466
  • 5
  • 29
  • 45
4

This means you did not created method names starting with test in following test cases class what you running currently

1

I was able to solve this error in my case--that is, running tests with a <junit> Ant task--by pointing to a 1.7 or later version of Ant. Ant 1.7+ honors nested <classpath> elements, in which I was pointing to a JUnit 4.x jar, which as CodeSpelunker indicated understands @Test annotations. http://ant.apache.org/faq.html#delegating-classloader provided the aha moment for me.

1

I'm using mockk in Kotlin for Android and I had this error.

My class was declared like this (autogenerated by Android Studio):

class MyClassTest : TestCase() {

but removing TestCase fixed the error

class MyClassTest {
MSpeed
  • 8,153
  • 7
  • 49
  • 61