简体   繁体   English

如何制作一个bat文件并使用JUnit4 Test Suite(不带Eclipse但使用命令行)对其进行测试?

[英]How to make a bat file and test with it a JUnit4 Test Suite without Eclipse but with Command Line?

I finished my two projects, one is a real one, and the other simulates a server that just generates some data, and now i made a junit test suite to test it both and all works. 我完成了两个项目,一个是真实的项目,另一个模拟了只生成一些数据的服务器,现在我制作了一个junit测试套件来测试它和所有工程。

Now is the time to send the real project together with the tests to a friend that made the real server project, that generates real data. 现在是时候将真实项目与测试一起发送给创建真实服务器项目的朋友了,后者会生成真实数据。

So I need now to prepare the tests somehow so he can just run them on Command Line, but I have no idea how to do that. 因此,我现在需要以某种方式准备测试,以便他可以在命令行上运行它们,但是我不知道该怎么做。

I searched a little on the net, and there was no way to run a test suite from the command line...and I hope you can help me. 我在网上搜索了一下,但无法从命令行运行测试套件……希望您能为我提供帮助。

Here is what I have in the test project: 这是我在测试项目中拥有的:

实际项目的测试

The class AllTests is a test suite, from witch I can run all the tests listed in it: AllTests类是一个测试套件,我可以运行其中列出的所有测试:

package test.dss;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({
    TestAddAndDeleteScript.class,
    TestEnumerateScripts.class,
    TestEnumerateTemplates.class,
    TestExecute.class,
    TestGetAllImportsList.class,
    TestGetBindings.class, 
    TestGetSource.class,    
    TestGetTemplate.class,
    TestLogin.class, 
    TestLogout.class, 
    TestOpenAndCloseFile.class,
    TestReloadLastLog.class,
    TestSetDates.class, 
    TestSetPatientList.class,
    TestStartStopTimer.class, 
    TestUpdateBindingParameters.class,
    TestUpdateScript.class,
    TestUpdateSharedUserList.class,
    TestUpdateTextArea.class
})
public class AllTests {

}

Then there are the tests that are for the other project: 然后是针对另一个项目的测试:

另一个项目的测试

With a similar code in the AllTests class: 在AllTests类中使用类似的代码:

package test.mw;

import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;

@RunWith(Suite.class)
@SuiteClasses({
    TestEnumerateParams.class,  
    TestEnumeratePatients.class, // za properties, pogledati red 55
    TestEnumerateScripts.class,
    TestGetAll.class,
    TestGetResults.class,
    TestLogin.class,
    TestLogout.class,
    TestRaiseAlarm.class,
    TestRegisterUnregisterScript.class,
    TestSaveResult.class
})
public class AllTests {

}

Now, I removed the tests from the workspace, and placed it on the desktop and have to figure out how to test it in command line, while my two projects run in elipse on localhost. 现在,我从工作区中删除了测试,并将其放在桌面上,必须弄清楚如何在命令行中对其进行测试,而我的两个项目在localhost上以椭圆形运行。

On top, I wanna create a BAT file witch my friend can just run (from the command line) and test his part (the mw part). 最重要的是,我想创建一个BAT文件,我的朋友可以从命令行运行它并测试他的部分(MW部分)。

Yeah, I forgot to mention, all the jars I need to run the tests are in the JRE System Library, JUnit 4 and referenced Libraries that are from the lib folder. 是的,我忘了提一下,我运行测试所需的所有jar文件都位于JRE系统库,JUnit 4和来自lib文件夹的引用库中。

So, I created a CMD Tests folder on the desktop, and copied all the files from the tests, and it looks like this: 因此,我在桌面上创建了CMD Tests文件夹,并复制了测试中的所有文件,如下所示:

测试文件夹上的dekstop

So here are the two parts of my question: a) How to test them all at once with the two test suites? 因此,这是我的问题的两个部分:a)如何使用两个测试套件同时对它们进行测试? ab) If there is no way, how to test each class individually? ab)如果没有办法,如何分别测试每个班级? b) How to make a bat file to run it all at once? b)如何制作一个bat文件以一次全部运行?

Please help. 请帮忙。

There is no need to create two test suites if you want to test them together. 如果要一起测试两个测试套件,则无需创建两个测试套件。 Just place all of the test classes into single Suite. 只需将所有测试类放入单个Suite中即可。

But running tests from two suites will look somehow like this: 但是从两个套件运行测试将看起来像这样:

java -cp "lib/*;bin" org.junit.runner.JUnitCore test.dss.AllTests test.mv.AllTests

Just place a .bat file in the root of your project with this content and you're ready to go. 只需将.bat文件和该内容放置在项目的根目录中,就可以开始使用了。

You can also use the same command for running a particular test, means something like: 您还可以使用相同的命令来运行特定的测试,这意味着:

java -cp "lib/*;bin" org.junit.runner.JUnitCore test.dss.TestExecute

Note: I don't know how you compile your classes. 注意:我不知道您如何编译课程。 I guess all of them are in bin folder. 我猜它们都在bin文件夹中。 If they are not just add the appropriate folder to the -cp section. 如果不是,则仅将适当的文件夹添加到-cp部分。

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

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