TestNG 未在 eclipse 上运行测试

问题描述 投票:0回答:3

知道为什么 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 -->
java eclipse selenium automation testng
3个回答
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();
        }

    }

0
投票
  1. 检查您的计算机上是否存在
    TestNG
    的 Eclipse 插件。
  2. 如果没有从帮助 => Eclipse Marketplace 安装最新版本。
  3. 重新启动 Eclipse。

0
投票

我之前也遇到过这个问题。

我刚刚改变了

import org.junit.Test;

import org.testng.annotations.Test;

并且成功了。

© www.soinside.com 2019 - 2024. All rights reserved.