2017-10-16 118 views
0

任何想法为什么TestNG未运行我的测试? 这是类代码(JAVA):TestNG未在eclipse上运行测试

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 --> 
+0

你不应该为你的测试代码需要'main()'方法,而且我的猜测是试图使用一个方法完全绕过了TestNG。 – jsheeran

+0

我不确定'@ Test'方法是否可以有参数。无论如何,当你的测试方法运行时,它会从哪里得到'args'的值?补充说:他们可以,但也许你没有遵循这个规则,http://testng.org/doc/documentation-main.html#test-methods(见5.6)。 – SantiBailors

+0

从main方法中移除String数组参数并尝试。它可能有效 – Murthi

回答

1

我在这里发布一个演示模板为您的testng.You只需要一个类和declear 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. 检查是否Eclipse插件TestNG在你的机器上。
  2. 如果不是从Help => Eclipse Marketplace最新安装。
  3. 重新启动日食。