How do you organize tests in a modular Java project?
I am creating a modular build (using module-info.java) on GitHub, but when adding a module-info.java to the modules that I want modular, no tests can be executed...
How can I achieve this?
I am using the following versions:
- junit.jupiter version 5.3.0 (first take was also unsuccessful with version 5.2.0)
- maven-compiler-plugin version 3.8.0 (first take was also unsuccessful with version 3.7.0)
- maven-surefire-plugin version 2.22.0 (first take was also unsuccessful with version 2.21.0)
A typical error from the failing tests looks like:
java.lang.reflect.InaccessibleObjectException: Unable to make
com.github.jactor.rises.commons.dto.UserDtoTest() accessible: module
jactor.rises.commons does not "opens
com.github.jactor.rises.commons.dto" to unnamed module @65e98b1c
java maven java-9 junit5 jigsaw
add a comment |
I am creating a modular build (using module-info.java) on GitHub, but when adding a module-info.java to the modules that I want modular, no tests can be executed...
How can I achieve this?
I am using the following versions:
- junit.jupiter version 5.3.0 (first take was also unsuccessful with version 5.2.0)
- maven-compiler-plugin version 3.8.0 (first take was also unsuccessful with version 3.7.0)
- maven-surefire-plugin version 2.22.0 (first take was also unsuccessful with version 2.21.0)
A typical error from the failing tests looks like:
java.lang.reflect.InaccessibleObjectException: Unable to make
com.github.jactor.rises.commons.dto.UserDtoTest() accessible: module
jactor.rises.commons does not "opens
com.github.jactor.rises.commons.dto" to unnamed module @65e98b1c
java maven java-9 junit5 jigsaw
add a comment |
I am creating a modular build (using module-info.java) on GitHub, but when adding a module-info.java to the modules that I want modular, no tests can be executed...
How can I achieve this?
I am using the following versions:
- junit.jupiter version 5.3.0 (first take was also unsuccessful with version 5.2.0)
- maven-compiler-plugin version 3.8.0 (first take was also unsuccessful with version 3.7.0)
- maven-surefire-plugin version 2.22.0 (first take was also unsuccessful with version 2.21.0)
A typical error from the failing tests looks like:
java.lang.reflect.InaccessibleObjectException: Unable to make
com.github.jactor.rises.commons.dto.UserDtoTest() accessible: module
jactor.rises.commons does not "opens
com.github.jactor.rises.commons.dto" to unnamed module @65e98b1c
java maven java-9 junit5 jigsaw
I am creating a modular build (using module-info.java) on GitHub, but when adding a module-info.java to the modules that I want modular, no tests can be executed...
How can I achieve this?
I am using the following versions:
- junit.jupiter version 5.3.0 (first take was also unsuccessful with version 5.2.0)
- maven-compiler-plugin version 3.8.0 (first take was also unsuccessful with version 3.7.0)
- maven-surefire-plugin version 2.22.0 (first take was also unsuccessful with version 2.21.0)
A typical error from the failing tests looks like:
java.lang.reflect.InaccessibleObjectException: Unable to make
com.github.jactor.rises.commons.dto.UserDtoTest() accessible: module
jactor.rises.commons does not "opens
com.github.jactor.rises.commons.dto" to unnamed module @65e98b1c
java maven java-9 junit5 jigsaw
java maven java-9 junit5 jigsaw
edited Nov 29 '18 at 18:33
Naman
45.1k11102204
45.1k11102204
asked Aug 31 '18 at 6:54
jactor-risesjactor-rises
1359
1359
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Welcome to Testing In The Modular World!
Which kind of tests do you want write?
Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.
White-box tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:
- "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
- "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.
Blog
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world
Examples
Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint
Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it
Background and other resources
- https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
- https://github.com/forax/pro
- https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
|
show 4 more comments
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52110023%2fhow-do-you-organize-tests-in-a-modular-java-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Welcome to Testing In The Modular World!
Which kind of tests do you want write?
Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.
White-box tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:
- "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
- "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.
Blog
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world
Examples
Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint
Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it
Background and other resources
- https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
- https://github.com/forax/pro
- https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
|
show 4 more comments
Welcome to Testing In The Modular World!
Which kind of tests do you want write?
Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.
White-box tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:
- "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
- "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.
Blog
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world
Examples
Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint
Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it
Background and other resources
- https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
- https://github.com/forax/pro
- https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
|
show 4 more comments
Welcome to Testing In The Modular World!
Which kind of tests do you want write?
Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.
White-box tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:
- "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
- "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.
Blog
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world
Examples
Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint
Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it
Background and other resources
- https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
- https://github.com/forax/pro
- https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
Welcome to Testing In The Modular World!
Which kind of tests do you want write?
Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.
White-box tests: As it was from Day 1 you need to "blend in"/merge/shadow your test classes into your main classes or vice versa. Here you have mainly two ways to achieve this:
- "compile modular main sources" and "patch plain test sources" at test-runtime with some additional "JVM options hacking the Module system" to execute tests.
- "compile modular test sources" and "patch modular main sources" at compile-time to execute tests.
Blog
https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world
Examples
Work-in-progress blueprint https://github.com/sormuras/sandbox/tree/master/sors-modular-testing-blueprint
Integration tests starting with "modular-world-" at https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it
Background and other resources
- https://github.com/junit-team/junit5-samples/tree/master/junit5-modular-world
- https://github.com/forax/pro
- https://blog.codefx.org/java/five-command-line-options-to-hack-the-java-9-module-system/
edited Sep 12 '18 at 7:34
answered Aug 31 '18 at 7:20
SormurasSormuras
2,8041238
2,8041238
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
|
show 4 more comments
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
2
2
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
This is super uber level of description. I am pretty sure those examples would have a good CTR in the coming days. Thanks for making an answer collaborating those examples.
– Naman
Aug 31 '18 at 9:32
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
this is a bit "high level" coding and requires hard focus to achieve. i am trying to gain experience in the modular world of java, but this is hard to achieve, when there are no particular useful examples and little useful documentation of this... can you provide some "step-by-step" instructions? i need to fully remove my surefire-plugin?
– jactor-rises
Aug 31 '18 at 14:59
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
from what I am reading, it seems to me that the maven lifecycle needs to be adjusted, first a test compile (which compiles test classes and main classes into the same module) and test it, then if it is successful, it builds the module without test classes. black box/white box? too many considerations? I want to test all classes in my module (not only the exported ones)...
– jactor-rises
Aug 31 '18 at 15:14
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
@jactor-rises Have a look at this blueprint: github.com/sormuras/sandbox/tree/master/… -- it is still work-in-progress but outlines the idea(s) in a minimal running example.
– Sormuras
Sep 1 '18 at 12:26
1
1
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
Eclipse is just as confused. I'm sorry but standard tooling just doesn't support this approach.
– billmill
Sep 21 '18 at 12:11
|
show 4 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52110023%2fhow-do-you-organize-tests-in-a-modular-java-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown