【问题标题】:Eclipse Run As doesn't show Junit or testNG optionEclipse Run As 不显示 Junit 或 testNG 选项
【发布时间】:2013-04-23 03:39:49
【问题描述】:

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

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

3)点击 Window>show views>我可以看到 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");

  }


}

【问题讨论】:

    标签: eclipse testng junit4


    【解决方案1】:

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

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

    你可以在ecplise中下载import jar文件后下载Junit表单Here然后检查

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 您好,Cedric 为您提供建议。我通过添加以下几行来修改代码: 1) import org.junit.Test,cmets out testNG 的Test 注释; 2) 去掉main方法中的static关键字,取出main方法中的参数,然后给方法起一个不同的名字。 3)单击 Run As the Junit test 选项显示+代码工作。感谢您的帮助!
      【解决方案3】:

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

      【讨论】:

      • 我按照您的建议添加了 5 个导入。我可以从 Run As 部分看到 testNG,但 Junit 没有显示为选项。请按代码部分检查并告诉我该怎么做。谢谢!
      • 感谢您的建议,我修改了它用作 Junit 测试的代码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-01
      • 1970-01-01
      相关资源
      最近更新 更多