Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
601 views
in Technique[技术] by (71.8m points)

jar - 如何从jar / bat /运行独立的TestNG项目(How to run standalone TestNG project from jar/bat/)

I have a TestNG project.

(我有一个TestNG项目。)

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

(没有任何主类,当前它像“ Run As TestNG”一样运行。)

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.

(我想将其导出为可运行的jar或jar,以便任何人都可以从命令行命中命令并开始运行测试用例。)

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.

(我不使用蚂蚁或行家。)

Thanks

(谢谢)

  ask by itin translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I seem to have found the solution after a bit of googling.

(经过一番谷歌搜索后,我似乎已经找到了解决方案。)

This works fine in Eclipse (Juno).

(这在Eclipse(Juno)中工作正常。)

Say, you have a TestNG file named 'Tests.java'.

(假设您有一个名为“ Tests.java”的TestNG文件。)

As you rightly pointed out, there won't be a class with main method.

(正如您正确指出的那样,不会有带有main方法的类。)

So, we have to create a new Java class file under the same package.

(因此,我们必须在相同的程序包下创建一个新的Java类文件。)

Let us name it 'MainOne.java'.

(让我们将其命名为“ MainOne.java”。)

This will have a class with main method.

(这将有一个带有main方法的类。)

Here is the code you need:

(这是您需要的代码:)

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

    }

Run the 'MainOne.java' as a Java application.

(作为Java应用程序运行“ MainOne.java”。)

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

(然后右键单击程序包->导出->可运行的Jar [选择'MainOne'作为启动配置]->完成。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...