【问题标题】:TestNG not running test on eclipseTestNG 没有在 Eclipse 上运行测试
【发布时间】:2018-03-27 16:00:08
【问题描述】:

知道为什么 TestNG 没有运行我的测试吗? 这是类代码(java):

public class main {
@Test
public static void main(String[] args) throws AWTException, InterruptedException 

这是eclipse上的路径: enter image description here

这是 XML 文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test name="Test">
    <classes>
        <class name="test.main"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

【问题讨论】:

  • 您的测试代码不应该需要main() 方法,我猜想尝试使用它完全绕过了TestNG。
  • 我不确定@Test 方法可以有参数。无论如何,当你的测试方法运行时,它会从哪里得到args 的值?补充:他们可以,但也许你没有遵守规则,testng.org/doc/documentation-main.html#test-methods(见 5.6)。
  • 从 main 方法中删除字符串数组参数并尝试。它可能有效

标签: java eclipse selenium automation testng


【解决方案1】:

我在这里发布了你的 testng 的演示模板。你只需要上课并清除 webdriver。 @BeforeMethod 将在开始之前执行任何 @Test 然后 @AfterMethod 希望它会帮助你。

package stackoverflow;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.testng.annotations.*;

    public class DemoTestNGClass {
        public static WebDriver driver;
        @BeforeMethod
        public void setUp1() throws Exception {

            driver= new ChromeDriver();


        }
        @Test
        public void Homepage() throws InterruptedException {
    //Your operation
        }

        @Test
        public void ListingPage() throws InterruptedException {

    //Your operation
        }

        @AfterMethod
        public void afterresult(){
            driver.close();
        }

    }

【讨论】:

    【解决方案2】:
    1. 检查您的机器上是否存在TestNG 的Eclipse 插件。
    2. 如果不是从 Help => Eclipse Marketplace 安装最新版本。
    3. 重启 Eclipse。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-30
      • 2014-02-04
      • 1970-01-01
      • 2013-03-12
      • 2015-07-10
      • 2021-04-18
      • 2013-06-03
      • 1970-01-01
      相关资源
      最近更新 更多