xmolecules / jmolecules-integrations

Technology integration for jMolecules
Apache License 2.0
85 stars 23 forks source link

TestEngine with ID 'archunit' failed to discover tests #184

Closed sysmat closed 11 months ago

sysmat commented 1 year ago
        <dependency>
            <groupId>org.jmolecules</groupId>
            <artifactId>jmolecules-layered-architecture</artifactId>
            <version>1.7.0</version>
        </dependency>
<dependency>
            <groupId>com.tngtech.archunit</groupId>
            <artifactId>archunit-junit5</artifactId>
            <version>1.0.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.jmolecules.integrations</groupId>
            <artifactId>jmolecules-archunit</artifactId>
            <version>1.6.0</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
@DisplayName("testing architecture")
@AnalyzeClasses(packages = "si.arnes.avs.server")
public class AppTest {

    @ArchTest
    ArchRule RESORCE_NAMING = classes().that()
            .areAnnotatedWith(Path.class)
            .or().haveSimpleNameEndingWith("Resource").should().beAnnotatedWith(Path.class)
            .andShould().haveSimpleNameEndingWith("Resource")
            .because("REST endpoint should and with Resource name");

//    @ArchTest
//    ArchRule LAYER_DEPENDENCIES_ARE_RESPECTED = layeredArchitecture().consideringAllDependencies()
//            .layer("Resources").definedBy("si.arnes.avs.server.resources..")
//            .whereLayer("Resources").mayNotBeAccessedByAnyLayer();

    @ArchTest
    ArchRule IMPLEMENT_INTERFACE = theClass(AvsService.class).should().implement(AvsRestApi.class);

    @ArchTest
    ArchRule NO_USEGE_OF_AVS_SERVICE_IMPLEMENTATION = noClasses()
        .that().doNotHaveFullyQualifiedName(getClass().getName())
        .should().dependOnClassesThat().haveFullyQualifiedName(AvsService.class.getName());

    @ArchTest
    ArchRule DDD_RULES = JMoleculesDddRules.all(); // (2)

    @ArchTest
    ArchRule LAYER = JMoleculesArchitectureRules.ensureLayering();

}
odrotbohm commented 1 year ago

Can you be more specific on what "break" means? Do you have a minimal reproducible example?

sysmat commented 1 year ago
[ERROR] TestEngine with ID 'archunit' failed to discover tests

jmolecules.zip

thmuch commented 1 year ago

@sysmat @odrotbohm Same problem here (with Java 17).

Unfortunately, jmolecules-archunit 1.6.0 is not compatible with ArchUnit 1.0 or later. You have do downgrade to ArchUnit 0.23.1 to get JMoleculesDddRules and JMoleculesArchitectureRules find certain classes/methods at (test) runtime.

I think there were some API changes in ArchUnit after 0.23.1 which may cause these problems.

This also means you cannot use Java 20/21, as the ASM lib bundled with ArchUnit 0.23.1 cannot read bytecode from these new versions. But your Java 8 config should work.

odrotbohm commented 1 year ago

I'm not sure that I follow. There's not jmolecules-archunit in 1.6. Integrations are still in 0.x. Please make sure you use the BOM. The latest version (2023.1.0) pulls in jMolecules Integrations 0.17. The ArchUnit integration of that is in turn built against ArchUnit 1.1.

thmuch commented 1 year ago

Oh... I was using integrations 1.6.0 from https://mvnrepository.com/artifact/org.jmolecules.integrations/jmolecules-archunit Will try the BOM.

odrotbohm commented 1 year ago

Yeah, that was released by accident at some point and we unfortunately cannot get it out of Maven Central. :(

thmuch commented 1 year ago

The BOM works like charm, also with ArchUnit 1.1.0 and Java 21. Thanks for the quick help!

thmuch commented 1 year ago

@sysmat This should fix your problem, too. Either use the BOM (or, for a quick check, use jmolecules-archunit 0.17.0 explicitely).