如何在模块化Java项目中组织测试? [英] How do you organize tests in a modular Java project?

查看:162
本文介绍了如何在模块化Java项目中组织测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 GitHub ,但是当我将module-info.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...

我可以实现吗?

我使用的是以下版本:


  • junit .jupiter版本5.3.0(第一次使用版本5.2.0也不成功)

  • maven-compiler-plugin版本3.8.0(第一次使用版本3.7.0也不成功)

  • maven-surefire-plugin 2.22.0版(第一次拍摄版本2.21.0也不成功)

失败测试的典型错误如下:

A typical error from the failing tests looks like:


java.lang.reflect.InaccessibleObjectException:无法生成
com.github.jactor.rises.commons.dto.UserDtoTest()access:模块
jactor.rises.commons不会打开s
com.github.jactor.rises.commons.dtoto unnamed module @ 65e98b1c

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


推荐答案

欢迎来到在模块化世界中进行测试

您想要写哪种测试?

黑盒测试:创建一个仅测试项目(没有src / main目录)并声明src / test / java / module-info。 java模块描述符。

Black-box tests: Create a test-only project (no "src/main" directory) and declare a "src/test/java/module-info.java" module descriptor.

白盒测试:从第1天起,你需要融入/合并/隐藏你的将类测试到主类中,反之亦然。在这里你主要有两种方法来实现这个目的:

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:


  • 在编译运行时使用编译模块化主源和补丁普通测试源一些额外的JVM选项攻击模块系统来执行测试。

  • 编译模块化测试源和修补模块化主源在编译时执行测试。

https://sormuras.github.io/blog/2018-09-11-testing-in-the-modular -world

https://github.com/sormuras/junit-platform-maven-plugin/tree/master/src/it

  • 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/

这篇关于如何在模块化Java项目中组织测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆