简体   繁体   中英

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.

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:

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:

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.

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).

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.

So, I created a CMD Tests folder on the desktop, and copied all the files from the tests, and it looks like this:

测试文件夹上的dekstop

So here are the two parts of my question: a) How to test them all at once with the two test suites? ab) If there is no way, how to test each class individually? b) How to make a bat file to run it all at once?

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.

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.

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. If they are not just add the appropriate folder to the -cp section.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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