简体   繁体   English

如何创建Junit测试类并在可执行JAR中运行

[英]How to create a Junit Test Class and run in executable JAR

I have a Junit Test Project and I have been on your site finding answers on how to get my program to run from a command prompt. 我有一个Junit测试项目,我一直在你的网站上找到如何让我的程序从命令提示符运行的答案。

I can supply the code. 我可以提供代码。 I added a main method to the code that has the test class. 我在具有测试类的代码中添加了一个main方法。 I found an example that has this code in the main method: JUnitCore jCore = new JUnitCore(); 我找到了一个在main方法中有这个代码的例子:JUnitCore jCore = new JUnitCore(); jCore.run(); jCore.run();

But all that executes is the main method and not the test. 但所有执行的都是主要方法,而不是测试。 All of the other examples I see include the name of the class, bu when I add that to the command above it gives me an error. 我看到的所有其他示例都包括类的名称,当我将其添加到上面的命令时,它会给我一个错误。 I think it is because the main method is within the test class. 我认为这是因为main方法在测试类中。 My programs are .java and not .class so I at a lost as to what to do now. 我的程序是.java而不是.class,所以我迷失了现在该做什么。

I am not finding anything that shows the complete steps. 我找不到任何显示完整步骤的内容。 Should also add that I have not done Java for over 13 years so I am rusty. 还应该补充一点,我已经超过13年没用Java了,所以我生锈了。

Here is the code I tried: 这是我试过的代码:

public class Selenium_Email_TestCase {

private WebDriver driver;
private String baseUrl;
private boolean acceptNextAlert = true;
private StringBuffer verificationErrors = new StringBuffer();

public static void main(String[] args) {
    System.out.println("In main method");
    JUnitCore jCore = new JUnitCore();
    jCore.run(Selenium_Email_TestCase);
}
}

You must use the class object. 您必须使用类对象。

jCore.run(Selenium_Email_TestCase.class);

Don't forget to import Selenium_Email_TestCase if it resides in a different package. 如果它位于不同的包中,请不要忘记导入Selenium_Email_TestCase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM