0

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:

tests for the real 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:

The tests 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:

test folder on dekstop

So here are the two parts of my question: a) How to test them all at once with the two test suites? a.b) 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.

Elydasian
  • 2,016
  • 5
  • 23
  • 41
  • nope, there is described how to test a single class, but not the whole suite, and regardless, I dont know how to add my jars to the classpath and all.... – Elydasian Jul 28 '17 at 07:26
  • Maybe [this](https://stackoverflow.com/a/3997971/6707985) helps? – geisterfurz007 Jul 28 '17 at 07:29
  • 2
    less, the first one, is like this: C:\Users\OSI\Desktop\CMD Tests\Tests>java -cp junit.jar org.junit unner.JUnitCore TestLogin Error: Could not find or load main class org.junit.runner.JUnitCore, I dont know how to add the junit.jar to the cp, but he is in the JUnit4 folder witch can not be found in my test Tests folder(see the last picture) – Elydasian Jul 28 '17 at 07:30
  • And once I go to the lib folder, where I have placed the junit.jar file, and run the same command, there is a new error: Time: 0.003 There was 1 failure: 1) initializationError(org.junit.runner.JUnitCommandLineParseResult) java.lang.IllegalArgumentException: Could not find class [TestLogin].........................so I need help there.... – Elydasian Jul 28 '17 at 07:44

1 Answers1

1

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.

Sasha Shpota
  • 9,436
  • 14
  • 75
  • 148
  • thx man, you helped a lot, but it seems I have a problem, can you tell me where I have to be, to run this command in the command prompt? – Elydasian Aug 09 '17 at 11:52
  • and I have a problem, once i place it in the root folder and run it, there is a could not find class test.dss.Tests error – Elydasian Aug 09 '17 at 12:00
  • The file should be in the root folder of your project (the same directory where you have `src`, `build` and `lib`). `could not find class test.dss.Tests ` only means that there is no appropriate class file in the classpath. How do you build compile/build the project? You have to include folder with generated classes (files with `.class` extension) into `-cp` section – Sasha Shpota Aug 09 '17 at 12:43
  • all my .class files are in bin/test/dss and bin/test/mw – Elydasian Aug 09 '17 at 12:56
  • Updated the answer, try now – Sasha Shpota Aug 09 '17 at 17:12