请告诉我我的java代码是否正确?

时间:2011-03-14 06:55:51

标签: java junit selenium selenium-rc

当我运行java代码时,我收到以下错误。下面我给出了我的Java代码...如果我出错了请纠正我...

junit.framework.AssertionFailedError: No tests found in pass
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.TestSuite$1.runTest(TestSuite.java:90)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

import com.thoughtworks.selenium.*;
public class pass extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("https://secure02.monilink.co.uk/", "*chrome");
    }
    public pass() throws Exception {
/******** Below I am using my test environment URL **************/
        selenium.open("http:www.xxxxxxxxxxxxxx.com")
        selenium.type("username", "RSRK1");
        selenium.type("password", "");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.type("username", "S10");
        selenium.type("password", "56454");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Pay Credit Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=exact:DEF Credit Card ************2016 Due Date: 19/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Account");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Current Account Created for Testing Purpose 11111111114 Balance: INR 6000.00");
        selenium.waitForPageToLoad("30000");
        selenium.type("amount", "20.00");
        selenium.type("transferDate", "190211");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=View and Pay Bills");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+bill1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=B.S.N.L, PUNJAB INR 135.00 due by 27/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+account+or+card2_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Testing Account 11111111120 Balance: INR 1358.32");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "190211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Edit");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "200211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Logout");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Yes");
        selenium.waitForPageToLoad("30000");
    }
}

由于

3 个答案:

答案 0 :(得分:1)

pass()方法更改为testSomething()之类的内容。如果要运行JUnit,则需要使用test为方法名称添加前缀。或者,您可以使用@Test注释您的测试方法。

e.g:

import com.thoughtworks.selenium.*;

public class pass extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("https://secure02.monilink.co.uk/", "*chrome");
    }

    public testMePlease() throws Exception {

    }
}

答案 1 :(得分:0)

JUnit抱怨,因为找不到任何测试。您的所有测试代码都在构造函数中。创建一个前面带有@Test属性的void方法。把你的硒步骤放进去吧。然后JUnit会找到它并将其作为测试运行。

答案 2 :(得分:0)

用以下代码替换您的代码:

    import com.thoughtworks.selenium.*;
public class pass extends SeleneseTestCase {
    public void setUp() throws Exception {
        setUp("https://secure02.monilink.co.uk/", "*chrome");
    }
    public testPass() throws Exception {
/******** Below I am using my test environment URL **************/
        selenium.open("http:www.xxxxxxxxxxxxxx.com")
        selenium.type("username", "RSRK1");
        selenium.type("password", "");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.type("username", "S10");
        selenium.type("password", "56454");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Pay Credit Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Card");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=exact:DEF Credit Card ************2016 Due Date: 19/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Select Account");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Current Account Created for Testing Purpose 11111111114 Balance: INR 6000.00");
        selenium.waitForPageToLoad("30000");
        selenium.type("amount", "20.00");
        selenium.type("transferDate", "190211");
        selenium.click("_Continue1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Payments");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=View and Pay Bills");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+bill1_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=B.S.N.L, PUNJAB INR 135.00 due by 27/09/10");
        selenium.waitForPageToLoad("30000");
        selenium.click("_Select+account+or+card2_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Testing Account 11111111120 Balance: INR 1358.32");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "190211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Edit");
        selenium.waitForPageToLoad("30000");
        selenium.type("paymentDateString", "200211");
        selenium.click("_Continue3_button");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Confirm");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Main menu");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Logout");
        selenium.waitForPageToLoad("30000");
        selenium.click("link=Yes");
        selenium.waitForPageToLoad("30000");
    }
}