当前位置: 首页 > 知识库问答 >
问题:

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

施俊远
2023-03-14

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

当类文件作为TestNG测试运行时,我得到的测试Run=0。

问题会是什么?

我有testNg插件

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
===============================================

在这两种情况下,结果都是“Tests Run=0”。

任何帮助将不胜感激。

谢谢!

编辑:我找到了解决方案:我在我的. java文件中使用了一个“私人”方法。

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

欢迎任何意见。

谢谢!

共有3个答案

夏谦
2023-03-14

您需要将@Test注释添加到“private void WebDrive()”方法,或者将访问修饰符更改为public,即从private void WebDrive()更改为public。将WebDrive()公开作废的步骤

宋宇
2023-03-14

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

尹俊贤
2023-03-14

你应该在test(WebDrive)方法上添加@Test。我也不确定是否私有测试运行。所以交叉比对公众

 类似资料:
  • 我试图用TestNG并行运行一个示例测试项目。但它是在一个线程中顺序执行的。我漏掉什么了吗? 谢了。

  • 问题内容: 我们刚刚开始在我们的项目上使用Gradle和TestNG,所以我正在检查是否有任何测试失败实际上会使构建失败。我很惊讶地发现事实并非如此。正确地拾取并编译了测试,因此我看到了类文件。我也得到了运行的报告,但是显示0个测试(预期2个)。跑步给我以下内容: SuperSimpleTest.java: build.gradle包含: 我已经看过有关此主题的其他问题,并且找到了用作解决方法的提

  • 我们刚刚开始在我们的项目中使用Gradle和TestNG,所以我正在检查失败的任何测试是否真的失败了构建。我很惊讶地看到它没有。测试被正确地拾取和编译,所以我看到了类文件。我也收到了运行报告,但它说0个测试(预计为2个)。运行给我以下信息: SuperSimpleTest.java: 生成.gradle 包含: 我已经看了一下有关此主题的其他问题,在那里我发现了使用作为解决方法的提示(请参阅 ht

  • 类TestParallel.FirstTestClass线程ID:22名称:TestNG 类TestParallel.SecondTestClass线程ID:23名称:TestNG 类TestParallel.TestSetup线程ID:23名称:TestNG java.lang.NullPoInterException位于TestParallel.TestSetup.OnTestFailure(

  • 我试图通过testng运行简单的Cucumber/Java测试。xml。 所以,我有testng。xml: 我用的是runner。类,在其中我将路径/选项/etc设置为功能文件、步骤和报告: 但是当我运行testng时。xml作为TestNG套件,它: 1) 通过我自己的设想, 但是 我做错了什么?

  • 22.13.1.执行测试 测试从main构建过程中分离出来的,运行在一个单独的JVM中执行.Test任务允许控制这些如何发生. 有许多属性用于控制测试过程如何启动.这包括使用诸如系统属性,JVM参数和Java可执行文件。 可以指定是否要并行执行测试.Gradle通过同时运行多个测试进程提供并行执行测试.每个测试进程在同一时间只能执行一个测试,为了充分利用这一特性,一般不需要为tests任务做什么特