java项目如和测试,如何在模块化Java项目中组织测试?

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

解决方案

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

Examples

Background and other resources

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值