1.创建module-info,. 在包下new一个module-info文件
2.文件中请求使用哪个Module
requires ConnectTest;
3.在被请求的Module下同样创建一个module-info文件,出口哪个包(这里是哪个包,不是Module) exports ConnectClass;
4.完成操作之后就可以new出其他Module下的类了
5.附加:创建module-info文件以后,其他的包,例如@Test,也需要在module-info文件中配置指明位置
再次附加:好像直接在标红的代码上修复,添加依赖就可以了:
可以添加junit4的依赖,和junit5的依赖,两个都可以一起用
依赖
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit5.4">
<CLASSES>
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-api-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-platform-commons-1.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-params-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-engine-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-platform-engine-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library name="JUnit5.4">
<CLASSES>
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-api-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/opentest4j-1.1.1.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-platform-commons-1.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-params-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-jupiter-engine-5.4.2.jar!/" />
<root url="jar://$MODULE_DIR$/../ideatest/lib/junit-platform-engine-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>