TestNG 选项未显示在 Eclipse 的 RunAs 选项中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31384826/
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-09 05:34:22  来源:igfitidea点击:

TestNG option not showing in RunAs option in Eclipse

eclipsetestng

提问by AdityaK

I am using maven project in eclipse ide and added a testng dependency as:

我在 eclipse ide 中使用 maven 项目并添加了一个 testng 依赖项:

<dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.8</version>
        <scope>test</scope>
    </dependency>

but i am unable to see TestNg option when right click on any testclass

但是当右键单击任何测试类时,我无法看到 TestNg 选项

回答by Micha? Grzejszczak

That dependency alone is hardly enough. You need to install TestNG Eclipse pluginto be able to use it as you describe.

仅靠这种依赖是不够的。您需要安装TestNG Eclipse 插件才能按照您的描述使用它。

回答by Greg

Ensure you have at minimum Java JDK 7, which is required for TestNG. See requirements section of testng documentation.

确保您至少有 Java JDK 7,这是 TestNG 所必需的。请参阅testng 文档的要求部分。

If you have Java 1.6 or earlier, it won't load in Eclipse, you can figure this out by looking at the [workspace]/.metadata/.log file, you should see the error logged:

如果您使用的是 Java 1.6 或更早版本,它不会在 Eclipse 中加载,您可以通过查看 [workspace]/.metadata/.log 文件来解决这个问题,您应该会看到记录的错误:

!ENTRY org.testng.eclipse 4 0 2015-08-16 06:36:21.383
!MESSAGE FrameworkEvent ERROR
!STACK 0
org.osgi.framework.BundleException: Could not resolve module: org.testng.eclipse [432]
  Unresolved requirement: Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version=1.7))

回答by Greg

After you have installed TestNG eclipse plugin, you need to create a TestNG run configuration. From the menu bar select: Run > Run Configurations. Select 'TestNG' from the list and select 'New Lanuch Configuration'. In there select class, method, whatever you want to run.

安装 TestNG eclipse 插件后,您需要创建一个 TestNG 运行配置。从菜单栏中选择:运行 > 运行配置。从列表中选择“TestNG”并选择“New Lanuch Configuration”。在那里选择类,方法,无论你想运行什么。

You can also go to preferences > run/debug > launching and select your default launch configs (launch the selected resource or active editor). enter image description here

您还可以转到首选项 > 运行/调试 > 启动并选择您的默认启动配置(启动所选资源或活动编辑器)。 enter image description here

回答by CK-Chennakeshava Byrappa

check if the annotation @Test is missing before the actual test method.

在实际测试方法之前检查注释@Test 是否丢失。

回答by Rajesh Thakur

If in Run->Run configuration you can't able to see TestNG Pluin then First add TestNG plugIn and install it. You can follow the following steps Eclipse->Help->Install New Software->Add->Give Name As TestNG->put URL(http://beust.com/eclipse/)->Click Install

如果在 Run->Run 配置中你看不到 TestNG Pluin 那么首先添加 TestNG 插件并安装它。您可以按照以下步骤 Eclipse->Help->Install New Software->Add->Give Name As TestNG->put URL( http://beust.com/eclipse/)->点击安装

回答by Vijay Aaditya

I faced a similar issue this morning and I followed the below steps to get it resolved.

今天早上我遇到了类似的问题,我按照以下步骤解决了这个问题。

  1. Add TestNG library to Java Build Path
  2. The TestNG Class should have been created under src/test/java.
  1. 将 TestNG 库添加到 Java 构建路径
  2. TestNG 类应该已经在 src/test/java 下创建。

In my case, I had it created under src/main/resources which is why I reckon it had no run configuration. This confusion arose because I normally use simple project but this time I wanted to learn by selecting an archetype.

就我而言,我在 src/main/resources 下创建了它,这就是为什么我认为它没有运行配置。出现这种混淆是因为我通常使用简单的项目,但这次我想通过选择原型来学习。

回答by Sugat Shivsharan

I too was facing the same problem, here is what worked for me

我也面临同样的问题,这对我有用

  1. Add TestNG dependency in Maven.

  2. Add Eclipse plugin as shown in link : https://www.toolsqa.com/selenium-webdriver/install-testng/

  1. 在 Maven 中添加 TestNG 依赖项。

  2. 添加 Eclipse 插件,如链接所示:https: //www.toolsqa.com/selenium-webdriver/install-testng/

It will take some time to add the plugin. Run the test after the Eclipse restarts.

添加插件需要一些时间。在 Eclipse 重新启动后运行测试。

回答by Atishay Jain

I am working on TestNG in Eclipse, I have added maven dependency using maven:

我正在 Eclipse 中处理 TestNG,我使用 maven 添加了 maven 依赖项:

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.1.0</version>
</dependency>

When I tried to run my test file present in src/java/test folder, I can't see anything in RunAs, then I followed below steps:

当我尝试运行 src/java/test 文件夹中的测试文件时,我在 RunAs 中看不到任何内容,然后我按照以下步骤操作:

Goto Help->Install new Software-> Click on Add button->

转到帮助-> 安装新软件-> 单击添加按钮->

  1. Name= TestNG
  2. Location=https://dl.bintray.com/testng-team/testng-eclipse-release/7.1.0/
  1. 名称= TestNG
  2. 位置= https://dl.bintray.com/testng-team/testng-eclipse-release/7.1.0/

NOTE:7.1.0 is my TestNG version, you can change this to your version.

注意:7.1.0 是我的 TestNG 版本,您可以将其更改为您的版本。

It will show you TestNG -> Check it and install it -> Restart Eclipse. Now you can see TestNGTest option in your Run As option.

它将向您显示 TestNG -> 检查并安装它 -> 重新启动 Eclipse。现在您可以在 Run As 选项中看到 TestNGTest 选项。

For more information, check READMEfile in GitHub Repo: https://github.com/cbeust/testng-eclipse

有关更多信息,请查看GitHub Repo 中的README文件:https: //github.com/cbeust/testng-eclipse

回答by Rocky

This is the simple solution that worked for me. Just Add Library of TestNG.

这是对我有用的简单解决方案。只需添加TestNG库。

Right click on your project > Configure Build Path > Add Library > TestNG > Next, Next, Finish.

右键单击您的项目 > 配置构建路径 > 添加库 > TestNG > 下一步、下一步、完成。