TestNG - 测试执行但测试运行= 0

时间:2014-04-01 00:05:07

标签: eclipse selenium-webdriver testng

我试图在Eclipse中使用Selenium运行TestNG。

当Class文件作为TestNG测试运行时,我得到测试运行= 0.

问题是什么?

我有testNg插件& jar文件已配置。

testng.xml文件:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="WikiTestSuite" verbose="3" parallel="methods">
    <test name="WikiTestCase">
        <classes>
            <class name="com.selenium.WebDriverTest" />
        </classes>
    </test>
</suite>

类:

WebDriverTest类

package com.selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

@Test
public class WebDriverTest extends BrowserInstance{

    private void WebDrive() {

        // navigate to specified browser
        wDriver.get("http://www.wikipedia.com");

        // assert wikipedia is opened
        Assert.assertEquals(wDriver.getTitle(), "http://www.wikipedia.com");
        System.out.println("Page title is correct. PASS!");
    }

}

BrowserInstance类

package com.selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;

public class BrowserInstance {
    // initialize webdriver object reference
    WebDriver wDriver;

    @BeforeMethod
    public void launchBrowser() {

        wDriver = new FirefoxDriver();
        System.out.println("In launchBrowser method");
    }

    @AfterMethod
    public void closeBrowser() {
        wDriver.close();
        wDriver.quit();
        System.out.println("In closeBrowser method");
    }
}

注意:

当我将testing.xml文件作为TestNG Suite运行时,结果是

[TestRunner] Running the tests in 'WikiTestCase' with parallel mode:methods
[RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@7426dbec priority: 10
[TestClass] Creating TestClass for [ClassImpl class=com.selenium.WebDriverTest]
[TestNG] Running:
  /Users/developer/Documents/workspace/SeleniumTest1/lib/testng.xml

[SuiteRunner] Created 1 TestRunners
[TestRunner] Running test WikiTestCase on 1  classes,  included groups:[] excluded groups:[]
===== Test class
com.selenium.WebDriverTest
  @BeforeMethod BrowserInstance.launchBrowser()[pri:0, instance:com.selenium.WebDriverTest@4979935d]
  @AfterMethod BrowserInstance.closeBrowser()[pri:0, instance:com.selenium.WebDriverTest@4979935d]
======
===== Invoked methods
=====
Creating /Users/developer/Documents/workspace/SeleniumTest1/test-output/WikiTestSuite/WikiTestCase.html
Creating /Users/developer/Documents/workspace/SeleniumTest1/test-output/WikiTestSuite/WikiTestCase.xml

===============================================
    WikiTestCase
    Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
WikiTestSuite
Total tests run: 0, Failures: 0, Skips: 0
===============================================

当我将.java文件作为TestNG测试运行时,结果是

[TestNG] Running:
  /private/var/folders/q6/xqd3z8fx69z05pbclbx_bj740000gp/T/testng-eclipse--953413131/testng-customsuite.xml


===============================================
    Default test
    Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
Suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================

在这两种情况下,结果都是&#34;测试运行= 0&#34;。

非常感谢任何帮助。

谢谢!

修改 我找到了解决方案:我使用了私人&#39;我的.java文件中的方法。

我能够纠正错误,但我现在想知道为什么TestNG不运行私有方法。

欢迎任何输入。

谢谢!

3 个答案:

答案 0 :(得分:0)

你应该添加&#34; @ Test&#34; on test(WebDrive)方法。我也不确定私人测试是否运行。所以与公众交叉检查

答案 1 :(得分:0)

我检查过,即使是默认的访问修饰符也不起作用,你必须为testng指定为public才能运行你的方法。

答案 2 :(得分:-2)

您需要将@Test注释添加到&#34; private void WebDrive()&#34;方法或将访问修饰符更改为public,即来自private void WebDrive()。 to public void WebDrive()