JUnit on application project

Hello,
I have seen in the documentation that it is possible to run JUnit testcases on the simulator. However I did not manage to get it running.
I am using MicroEJ SDK Version 19.05.
I added in the windows->properties->Ant the path to the virtual device and in my module.ivy:
<dependency conf="test->*" org="ej.library.test" name="junit" rev="1.5.0" onf="test->*" />
I then created a testcase in the src/test/java directory and added it to the source directories in the project build path.
When I build the project, I get in JUnit tests the following error;

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_231\lib\tools.jar

I tried to use the sample project (GitHub - MicroEJ/Example-Sandboxed-JUnit: This project gathers simple sandboxed applications tested with JUnit.) but even after the migration, It makes the same error.

Here are my questions:
1- Is there a way to skip the javadoc generation that can break the build befiore the Junit testcases get a chance to run?
2- How to make my tests actually run?
3- Will it be possible then to use the debugger on the tests while running on the simulator (as for a normal Junit testcase on Eclipse) ?

Thanks for your help!
Stéphane

Hello @stephane_picodev,

1- Is there a way to skip the javadoc generation that can break the build befiore the Junit testcases get a chance to run?

You can add the property javadoc.failonerror and set it to false. This will keep running the javadoc generation but will not fail on error.

2- How to make my tests actually run?

There are different ways to run a test:

  • Tests are generated in src-adpgenerated/junit/java/ and each contains a main that can be run
  • Automatic run with the project build

3- Will it be possible then to use the debugger on the tests while running on the simulator (as for a normal Junit testcase on Eclipse) ?

Yes, the test from src-adpgenerated can be runned using the debbugger.

You can find more information there Test Suite with JUnit — MicroEJ Documentation

Regards,

Thanks for your help.
However, I still can’t get it running correctly.
1- Where the property should be defined?
2- How to run the test without the error I get
(Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_231\lib\tools.jar) ?
Actually the Juit process seems to run, but the testcase is not executed. I suppose something is nto configured correctly but I followed the documentation and the setup is not working.
Thank you Pierre!

Kind regards,
Stéphane

Hi @stephane_picodev,

1- Where the property should be defined?

You can define the property either

  • Adding the property in windows->preferences->Ant->Runtime
  • Modifying your module.ivy file, in the tag ea:build, add a new tag <ea:property name="javadoc.failonerror" value="false" />

2- How to run the test without the error I get

Do you have the junit test cases generated in src-adpgenerated/junit/java/ ?
Can you send more lines of your log ?

Regaards,

Thank you Pierre.
The ant build gives during the execution of the testscases:

[testsuite:javaTestsuite] [I3] - No custom property file found for this test:
[testsuite:javaTestsuite] Running test (1/10): I:\Projets.…\target~\test\classes\com.…wa\domain\RestManagerTest.class
[testsuite:javaTestsuite] Test classname: com…wa.domain.RestManagerTest
[testsuite:javaTestsuite] Test output name: com…a.domain.RestManagerTest
[testsuite:javaTestsuite] > Test ended as failure

The log of each individual JUnit testxase run (from the report XML file) gives:

Unable to locate tools.jar. Expected to find it in C:\Program Files\Java\jre1.8.0_231\lib\tools.jar

Buildfile: D:\App\MicroEJ-Studio\rcp\configuration\org.eclipse.osgi\457\data\repositories\microej-build-repository\com\is2t\easyant\plugins\microej-testsuite\3.3.2\microej-testsuite-harness-s3-3.3.2.xml

traceAnalyzer/definition:

runTest:

[mkdir] Created dir: I:\Projets\ ... \target~\test\xml\test\20200427-1431-17\com.....wa.domain._SingleTest_RestManagerTest_testUpdateTime\null294835513

activity/microej:

 [echo] =============== [ Initialization Stage ] ===============

check/OS/job:

isWinXP:

check/OS:

target/define:

platform/constants:

init/vd/embeded-applications:

BUILD FAILED

D:\App\MicroEJ-Studio\rcp\configuration\org.eclipse.osgi\457\data\repositories\microej-build-repository\com\is2t\easyant\plugins\microej-testsuite\3.3.2\microej-testsuite-harness-s3-3.3.2.xml:33: The following error occurred while executing this line:

I:\Projets.…wa\target~\platform\scripts\init-vd\vd-init.xml:11: java.lang.RuntimeException: java.nio.file.NoSuchFileException: I:\Projets.…wa\target~\test\xml\test\20200427-1431-17\bin\META-INF\MANIFEST.MF

*at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:397)

*at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:449)

*at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:406)

*at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:402)

*at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:155)

*at javax.script.AbstractScriptEngine.eval(Unknown Source)

*at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

*at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

*at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

*at java.lang.reflect.Method.invoke(Unknown Source)

*at org.apache.tools.ant.util.ReflectUtil.invoke(ReflectUtil.java:109)

*at org.apache.tools.ant.util.ReflectWrapper.invoke(ReflectWrapper.java:81)

*at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:103)

*at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)

*at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:53)

*at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)

*at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)

*at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

*at java.lang.reflect.Method.invoke(Unknown Source)

*at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

*at org.apache.tools.ant.Task.perform(Task.java:348)

*at org.apache.tools.ant.Target.execute(Target.java:435)

*at org.apache.tools.ant.Target.performTasks(Target.java:456)

*at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)

*at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)

*at org.apache.tools.ant.Project.executeTargets(Project.java:1260)

*at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)

*at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)

*at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

*at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

*at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

*at java.lang.reflect.Method.invoke(Unknown Source)

*at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)

*at org.apache.tools.ant.Task.perform(Task.java:348)

*at org.apache.tools.ant.Target.execute(Target.java:435)

*at org.apache.tools.ant.Target.performTasks(Target.java:456)

*at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)

*at org.apache.tools.ant.Project.executeTarget(Project.java:1376)

*at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)

*at org.apache.tools.ant.Project.executeTargets(Project.java:1260)

*at org.apache.tools.ant.Main.runBuild(Main.java:857)

*at org.apache.tools.ant.Main.startAnt(Main.java:236)

*at org.apache.tools.ant.launch.Launcher.run(Launcher.java:287)

*at org.apache.tools.ant.launch.Launcher.main(Launcher.java:113)

Caused by: java.nio.file.NoSuchFileException: I:\Projets…wa\target~\test\xml\test\20200427-1431-17\bin\META-INF\MANIFEST.MF

*at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)

*at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)

*at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)

*at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)

*at java.nio.file.Files.newByteChannel(Unknown Source)

*at java.nio.file.Files.newByteChannel(Unknown Source)

*at java.nio.file.spi.FileSystemProvider.newInputStream(Unknown Source)

*at java.nio.file.Files.newInputStream(Unknown Source)

*at jdk.nashorn.internal.scripts.Script$^eval_.:program(:4)

*at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:637)

*at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:494)

*at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393)

*… 43 more

Total time: 3 seconds

Then when I select a Testcase in src-adpgenerated/junit/java in Eclipse, right click and select debug as MicroEJ Application it starts the emulator and runs my application but not the JUnit Testcase
Thanks for your help !
Kind regards,
Stéphane

Hi Stéphane,

OK, I did not get that you were using a virtual device with the Studio. Unfortunately we have a known issue for running the junit test cases with the virtual device. It will be fixed for the next firmware released.

Regards,

Pierre

Ah ok Pierre.
Does it means it would work on the target evaluation board? Or do I need to change the architecture (for JUnit this could be manageable workaround)?
Regards,
Pierre

Currently, you can run the test on the simulator using the src-generated main files.

To run the tests on the build (they are run on the simulator), you will need to wait for a new virtual device.

If you want to run them now, you could use an SDK platform with an evaluation license.

Regards,