如何从jar / bat /运行独立的TestNG项目 [英] How to run standalone TestNG project from jar/bat/

查看:149
本文介绍了如何从jar / bat /运行独立的TestNG项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TestNG项目。没有任何主类,目前它正在运行,如Run As TestNG。

I have a TestNG project. Don't have any main class, currently it is running like "Run As TestNG".

我想将它导出为runnable jar或jar,这样任何人都可以从命令行命中命令并且测试用例开始运行。

I want to export it as runnable jar or jar so that any one can just hit a command from command line and test cases start running.

任何人都可以帮我解决这个问题吗?或建议任何其他方式以可运行的形式提供代码......

Could any one help me out in this? or suggest any other way to deliver the code in runnable form...

我没有使用蚂蚁或专家。

I am not using ant or maven.

谢谢

推荐答案

我似乎在google搜索后找到了解决方案。这在Eclipse(Juno)中运行良好。

I seem to have found the solution after a bit of googling. This works fine in Eclipse (Juno).

比如说,你有一个名为'Tests.java'的TestNG文件。正如你正确指出的那样,没有一个主类方法。
因此,我们必须在同一个包下创建一个新的Java类文件。我们将其命名为'MainOne.java'。这将有一个主要方法的类。

Say, you have a TestNG file named 'Tests.java'. As you rightly pointed out, there won't be a class with main method. So, we have to create a new Java class file under the same package. Let us name it 'MainOne.java'. This will have a class with main method.

以下是您需要的代码:

import com.beust.testng.TestNG;

public class MainOne {

    public static void main(String[] args) {
        TestNG testng = new TestNG();
         Class[] classes = new Class[]{Tests.class};
         testng.setTestClasses(classes);
         testng.run();

    }

将'MainOne.java'作为Java应用程序运行。然后右键单击包 - > Export - > Runnable Jar [选择'MainOne'作为启动配置] - >完成。

Run the 'MainOne.java' as a Java application. Then right click on the package -> Export -> Runnable Jar [Choose 'MainOne' as Launch Configuration] -> Finish.

这篇关于如何从jar / bat /运行独立的TestNG项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆