Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing use case for 'rule to handle more than one test class matching impl class' #1367

Open
krzysztof-owczarek opened this issue Oct 23, 2024 · 0 comments

Comments

@krzysztof-owczarek
Copy link

Linked to: #920

Structure like this:

com/tngtech/archunit/library/testclasses/packages/correct/onlyoneimplmatchingdir1/OnlyOneImplementationHaveTestAndItIsMatchingImplPackage.java
com/tngtech/archunit/library/testclasses/packages/correct/onlyoneimplmatchingdir1/OnlyOneImplementationHaveTestAndItIsMatchingImplPackageTest.java
com/tngtech/archunit/library/testclasses/packages/incorrect/onlyoneimplmatchingdir2/OnlyOneImplementationHaveTestAndItIsMatchingImplPackage.java

will fail test:

    @Test
    public void should_pass_when_only_one_of_two_implementations_have_test_class_and_it_is_in_implementation_package() {
        assertThatRule(testClassesShouldResideInTheSamePackageAsImplementation())
                .checking(new ClassFileImporter().importPackagesOf(
                        OnlyOneImplementationHaveTestAndItIsMatchingImplPackage.class,
                    com.tngtech.archunit.library.testclasses.packages.incorrect.onlyoneimplmatchingdir2.OnlyOneImplementationHaveTestAndItIsMatchingImplPackage.class
                ))
                .hasNoViolation();
    }

Right now it seems that if one of the implementation has a test in the correct package and the other one (with the same name) has no test at all, the possibleTestClasses will find the test in the wrong package and fail the rule. You have to add at least a blank test class in the right package for each implementation to make the rule pass.

Possible solution could be:

  • keeping track of the implementation class list,
  • checking if the possibleTestClasses have no matching implementation in the right package and discard it from checklist of another implementation class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant