Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Resolution of test classes failing when the dependency they originate is Java 9/10 module ?(Java 10 migration is not easy and Java 11 is almost at our door step...)
Resolution of test classes failing when the dependency they originate is Java 9/10 module ? [message #1792704] Sun, 22 July 2018 22:12 Go to next message
NoDataFound - is currently offline NoDataFound -Friend
Messages: 3
Registered: October 2017
Junior Member
Hello,

I am using Photon since it ships with Java 9 and 10 supports: I am trying to migrate all my module to Java 10 and try to make it work with Maven 3.5.4/Eclipse Photon and of course Java 10.

My problem is simple : I am using Junit 5 and the extension mechanism. To that end, I've made a Java 10 module named "testtoolbox". It contains those extension that I want to share with my other module.

In terms of Maven and Eclipse, this gives:

testtoolbox
- requires org.assertj.core, com.github.marschall.memoryfilesystem, org.junit.jupiter.api (transitive);
org.junit.jupiter.engine, org.junit.jupiter.params, org.junit.platform.commons, org.mockito and org.opentest4j;

moduleA:
- have a test dependency on testtoolbox in maven

Now, I have a test using my class from testtoolbox, and it fails to compile due to missing require in module-info: I don't really want to add them, since it would mean my module is depending on test dependency which is not what I want.

@ExtendWith({ TestToolBoxExtension1.class }) // TestToolBoxExtension1 can not be resolved to a type
class ModuleASomeClassTest {
  @Test
  public void testMethod1(SomeStuffFromTestToolBox e) { // SomeStuffFromTestToolBox can not be resolved to a type
    ...
  }
}


I have (at least) two compilation errors because Eclipse sees my test dependency as a Java 10 modules (which is the case).

- The quick fix prompt me to "add require testtoolbox".
- These errors are not shown in the Markers/Problem view: I only have a "The type [...] is not exported from this module" marker for the test class ModuleASomeClassTest (so in moduleA).
- Eclipse is not capable to "Run as Junit" test.

I don't know what to do :

- if I follow what is done for other test dependency, the class TestToolBoxExtension1 and SomeStuffFromTestToolBox should be in the class path and there should not be any compilation error.
- I tried to remove the module-info from testtoolbox, and while this work, what will happens when Java decide to drop the class path ?
- ... the solution above works, but I now have a test that fails in Maven and which work in Eclipse: the test fails due to Class::getResource whose behavior differ from Java 8 (where it worked) and 10 (where it fails). It seems that Java see the testtoolbox as an "unnamed module" with or without module-info (this might be some consequence due to Maven sending the module in the class path rather than in the module path).
- Should i create a test module-info.java ?

Regards,
NoDataFound

Re: Resolution of test classes failing when the dependency they originate is Java 9/10 module ? [message #1792783 is a reply to message #1792704] Tue, 24 July 2018 03:52 Go to previous messageGo to next message
Sarika Sinha is currently offline Sarika SinhaFriend
Messages: 80
Registered: February 2010
Location: Bangalore, India
Member
You can use the new feature of marking a source folder as a test folder : https://www.eclipse.org/eclipse/news/4.8/M5/index.html#jdt-test-sources

Sarika Sinha
JDT Programmer
Re: Resolution of test classes failing when the dependency they originate is Java 9/10 module ? [message #1792834 is a reply to message #1792704] Tue, 24 July 2018 14:57 Go to previous messageGo to next message
NoDataFound - is currently offline NoDataFound -Friend
Messages: 3
Registered: October 2017
Junior Member
Hello,

Thanks for the reply but I think you probably don't use m2e because that is already done and it does not help with the problem.

The dependency is indeed a test dependency and classified as such in Eclipse. However, it is also recognized as a Java 9/10 module and Eclipse produce errors while maven don't produce them (but the testtoolbox module is still seen as a module, given how it fails to load a module resource).

As I can't expose the project I'm working on, I'll try to scrap a attach an example of what I'm meaning.
Re: Resolution of test classes failing when the dependency they originate is Java 9/10 module ? [message #1792840 is a reply to message #1792834] Tue, 24 July 2018 21:58 Go to previous message
NoDataFound - is currently offline NoDataFound -Friend
Messages: 3
Registered: October 2017
Junior Member
As promised, here is a sample : the ZIP file contains the following:

- a parent project
- first module unittest-shared containing classes that are shared across module
- second module mockito-jpms-usecase which provide an example of the errors I encounters;

This needs to be compiled with Maven 3.5.4 + a toolchains containing Java 10 (see https://maven.apache.org/ref/3.5.4/maven-core/toolchains.html ).

The project needs to be imported as "Maven project" in Eclipse. It should resolve itself.

For reference, it also present a problem with Mockito : https://stackoverflow.com/questions/50634322/java-modules-accessibility-problems-for-mockito-2-19-0 for which I fail to see what I can really do beside opening my module (which I don't want).

The ATest contains 5 tests, the ExtensionTest contains one test.

- In Maven, all tests are found: 3 are failing because Mockito can't access the class it tries to mock. It is dues to missing opens to package which mockito access, but I don't want to open more than needed (eg: the opens needs to be a "wide opens" and it needs to go in the module-info which is ugly).
- In Eclipse, all tests are found from src/test/java, but no test are found in ExtensionTest.java (eg: there is no Run As > JUnit Test), because it fails to compile as seen in https://www.eclipse.org/forums/index.php/fa/33489/0/

The console display this warning:

Quote:
WARNING: Unknown module: nodatafound.unittest_shared specified to --add-reads
Mock for E, hashCode: 1966355106
nodatafound.mjpmsuc.B@616fe72b



As a user, I expect to be able to run test from the class because I'm writing the test or fixing a test. There should be no error (and the error is only displayed in the editor).



[Updated on: Tue, 24 July 2018 23:37]

Report message to a moderator

Previous Topic:Eclipse Junit: java.lang.ClassNotFoundException
Next Topic:Can't set breakpoints in Spring after upgrade to Photon
Goto Forum:
  


Current Time: Wed Nov 14 17:11:27 GMT 2018

Powered by FUDForum. Page generated in 0.05174 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top