ArchUnit
ArchUnit copied to clipboard
TestEngine with ID 'archunit' failed to discover tests
- I'm new to this lib, idea is great, I follow https://www.archunit.org/userguide/html/000_Index.html#_junit_5
- java 8, Apache Maven 3.9.2, junit-jupiter:5.10.0-M1, archunit-junit5:1.0.1, maven-surefire-plugin:3.1.2, NetBeans:16
- when runing maven test I get: TestEngine with ID 'archunit' failed to discover tests
- unit test
@DisplayName("testing architecture")
@AnalyzeClasses(packages = "si.arnes.avs.server")
public class AppTest {
@ArchTest
@Test
void core_should_only_be_accessed_by_satellites() {
theClass(AvsRestApi.class)
.should().onlyBeAccessed().byClassesThat().implement(AvsService.class);
}
}
- In Netbeans on test file(Ctrl + F6) -> no test executed
ArchUnit works with any test framework that executes Java code. To use ArchUnit in such a context, include the core ArchUnit dependency from Maven Central:
In your docs, have I missed something?
public static final is the key factor to junit5 recognize test
- You don't need to annotate ArchUnit tests with
@Test. - There are two ways to use
@ArchTests:- Declaratively as
ArchRules:@ArchTest ArchRule rule = // ... - Imperatively as methods with a
JavaClassesparameter:@ArchTest void rule2(JavaClasses classes) { // ... rule.check(classes); }
public static finalin not needed in either case. - Declaratively as
TestEngine with ID 'archunit' failed to discover teststhe same is happening witharchunit-junit5:1.4.1maven-surefire-plugin:3.5.4junit-jupiter:5.14.0
Can you provide an example repository? Then I'll try to show you how to fix it.
- it is organization project, I can not share it
- it is very strange even with
mvn -Dmaven.surefire.debug testno extra information
[ERROR] See ...\target\surefire-reports for the individual test results.
[ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] There was an error in the forked process
[ERROR] TestEngine with ID 'archunit' failed to discover tests
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] TestEngine with ID 'archunit' failed to discover tests
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:631)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:285)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:250)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1337)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1135)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:969)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
[ERROR] at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.lang.reflect.Method.invoke(Method.java:498)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:255)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:201)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:361)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:314)
- my test case, produce
TestEngine with ID 'archunit' failed to discover tests
@ArchTest
static final ArchRule MDN_SHOULD_NOT_ACCESS_IMPLEMENTATIONS = noClasses()
.that()
.resideInAPackage("..mdm..")
.should()
.accessClassesThat()
.resideInAPackage("..implementations..");
@ArchTest
static final ArchRule MDM_SHOULD_BE_ACCESS_RESOURCES = classes()
.that()
.resideInAPackage("..mdm..")
.should()
.onlyBeAccessed()
.byAnyPackage("..resources..", "..mdm..", "..iga...");
- when I remove MDM_SHOULD_BE_ACCESS_RESOURCES then no error archunit