Eclipse Run As 不显示 Junit 或 testNG 选项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16160511/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 20:24:06  来源:igfitidea点击:

Eclipse Run As doesn't show Junit or testNG option

eclipsetestngjunit4

提问by user2061466

I am trying to execute a simple test case using Junit4 in Eclipse (version 3.7.0)

我正在尝试在 Eclipse(版本 3.7.0)中使用 Junit4 执行一个简单的测试用例

1) I click on the Run icon (next to the debug icon), then click on the Run As option, it only shows Java Application as an option 2) when I click on Run Configuration option, within the Create, Manage and run configuration window, I saw Junit and TestNG listed in the left pane

1) 我点击运行图标(在调试图标旁边),然后点击运行方式选项,它只显示 Java 应用程序作为一个选项 2)当我点击运行配置选项时,在创建、管理和运行配置中窗口,我看到左窗格中列出了 Junit 和 TestNG

3)click on Window>show views>I can see Junit and TestNG listed as an option

3)点击窗口>显示视图>我可以看到Junit和TestNG列为选项

Please advise me how to resolve this issue. Thanks!

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

Project Name: webDriverMethods

项目名称:webDriverMethods

below is my code

下面是我的代码

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");

  }


}

采纳答案by Cedric Beust

You can't add @Teston a static method with arguments, it will be ignored. This could possibly work with TestNG if you define a data provider but it's most likely not what you want. Test methods are regular methods on the class, see http://testng.orgfor examples.

您不能添加@Test带有参数的静态方法,它将被忽略。如果您定义数据提供程序,这可能适用于 TestNG,但很可能不是您想要的。测试方法是类上的常规方法,有关示例,请参见http://testng.org

回答by Ankit jain

Does you add Testng and Junit .Jar file in your current project, if you add TestNG and Junit jar file in your project then you can run your project with testng and Junit

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

you check herehow to install Testng in Ecplise

您检查here如何在 Ecplise 中安装 Testng

You can download Junit form Hereafter download import jar file in ecplise and then check

您可以在 ecplise 中下载导入 jar 文件后在此处下载 Junit 表单,然后检查

回答by niharika_neo

You need to have a method annotated with @Test for the plugins to recognize it as a TestNG test. Add an import of the testng test annotation to see run as-> TestNG as an option or impprt @Test from junit to see run as -> Junit, TestNG as an option.

您需要有一个用 @Test 注释的方法,以便插件将其识别为 TestNG 测试。添加 testng 测试注释的导入以查看 run as-> TestNG 作为选项或从 junit 导入 @Test 以查看 run as -> Junit, TestNG 作为选项。