2013-04-23 101 views
1

我试图执行在Eclipse中使用Junit4一个简单的测试用例(3.7.0版本)Eclipse的运行方式不显示的Junit TestNG的或选项

1)我的运行图标点击(旁边调试2)单击运行配置选项,在创建,管理和运行配置窗口中,我看到左侧窗格中列出了Junit和TestNG

3)单击窗口>显示视图>我能看到的Junit和TestNG作为一个选项列出

请告诉我如何解决 这个问题。谢谢!

项目名称:webDriverMethods

下面

是我的代码

import org.junit.*; 
import static org.junit.Assert.*; 
import java.util.*; 
import org.testng.annotations.*; 
import org.testng.annotations.Test; //added 5 imports for Junit and testNG 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class webDriverMethodsTest 
{ 
    @Test 
    public static void main(String[] args) 
    { 
    WebDriver driver = new FirefoxDriver(); 
    driver.get("http://www.google.com"); 

    } 


} 

回答

0

你不能在带参数的静态方法上添加@Test,它将被忽略。如果你定义了一个数据提供者,这可能与TestNG一起工作,但它很可能不是你想要的。测试方法是班上的常规方法,例如参见http://testng.org

+0

你好Cedric,建议。我通过添加这些行来修改代码:1)** import org.junit.Test **,注释掉testNG的Test注解; 2)在main方法中删除** static **关键字,取出main方法中的参数,然后给方法一个不同的名称。 3)点击运行随着显示的Junit测试选项+代码工作。谢谢您的帮助! – user2061466 2013-04-24 01:29:05

1

你是否TestNG的添加和JUnit .jar文件在当前项目中,如果你在你的项目中添加TestNG的和JUnit jar文件那么你可以用testng和Junit运行你的项目

你检查here如何在Ecplise安装Testng

您可以下载后导入jar文件下载Junit的形式Here在ecplise然后检查

0

你需要有@Test注释,以便插件的方法将其识别为一个TestNG的测试。添加testng测试注释的导入,以便将as-> TestNG作为选项运行,或者从junit中将impprt @Test运行为 - > Junit,TestNG作为选项运行。

+0

我按照您的建议添加了5个进口商品。我可以从运行方式部分看到testNG,但Junit不显示为选项。请检查代码部分,并告诉我该怎么做。谢谢! – user2061466 2013-04-23 12:18:56

+0

感谢您的建议,我修改了它作为Junit测试工作的代码。 – user2061466 2013-04-24 01:34:44

相关问题