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

General rule to test that class and its test are both at the same package #475

Closed
ars-java opened this issue Nov 23, 2020 · 11 comments · Fixed by #908
Closed

General rule to test that class and its test are both at the same package #475

ars-java opened this issue Nov 23, 2020 · 11 comments · Fixed by #908

Comments

@ars-java
Copy link

ars-java commented Nov 23, 2020

It will be convenient to have GeneralCodingRules.TEST_SHOULD_HAVE_SAME_PACKAGE rule to test that classes Xxx from /src/ and XxxTest from /test/ are both at the same package

@ars-java ars-java changed the title General rule to test that class and its are both at the same package General rule to test that class and its test are both at the same package Nov 23, 2020
@hankem
Copy link
Member

hankem commented Nov 24, 2020

You can define a custom @ArchTest like in #20 (comment).

@ars-java
Copy link
Author

ars-java commented Nov 24, 2020

Yes, I can. But I think that it's a useful common and reusable feature to add it to the library. It's more fundamental than restrictions for joda-time or JUL

@codecholeric
Copy link
Collaborator

I agree, even though I wonder if the naming pattern should be customizable 🤔
Like GeneralCodingRules.testsShouldResideInTheSamePackageIdentifyingTestsByName("$Test")), and someone else could write ...IdentifyingTestsByName("$IntegrationTest") or ...IdentifyingTestsByName("$Tests") for example.
Anyway, if you have time I would be happy to support you with a PR for this feature 😉 Or if anybody else wants to contribute. I think it would be a good starter task 😃 Otherwise I have to put it in my pipeline and implement it when I get to it, but looking at my task pipeline that could take a while 😞

@Rossalli
Copy link

Hi, @codecholeric! Could you please assign this to me? I would like to try help with this issue :)

Thanks!

@mslowiak
Copy link
Contributor

@Rossalli are you still working on that one? can I pick this up?

@Rossalli
Copy link

Hi @mslowiak, I'm working on that :)

@thatsIch
Copy link

thatsIch commented Jun 5, 2022

@Rossalli how is your progress?

@codecholeric
Copy link
Collaborator

Since the last comment from @Rossalli is from almost a year ago and there has been no reply to the last ping for over a month I would consider this issue open for grabs again...

@mslowiak
Copy link
Contributor

@codecholeric So, can I pick this up? :)

@codecholeric
Copy link
Collaborator

Yes, feel free to pick it up! (Sorry if you're really still working on it @Rossalli, but without any life sign for so long I can't block the issue forever)

@codecholeric codecholeric assigned mslowiak and unassigned Rossalli Jul 11, 2022
@codecholeric
Copy link
Collaborator

@mslowiak I assigned you to it for transparency, hope that's okay 😉

mslowiak added a commit to mslowiak/ArchUnit that referenced this issue Jul 11, 2022
mslowiak added a commit to mslowiak/ArchUnit that referenced this issue Jul 11, 2022
…in the same package as implementation class
mslowiak added a commit to mslowiak/ArchUnit that referenced this issue Jul 11, 2022
…in the same package as implementation class

Signed-off-by: Marcin Słowiak <[email protected]>
mslowiak added a commit to mslowiak/ArchUnit that referenced this issue Jul 11, 2022
…in the same package as implementation class

Signed-off-by: Marcin Słowiak <[email protected]>
codecholeric added a commit that referenced this issue Jul 13, 2022


This will add the library rule `GeneralCodingRules.testClassesShouldResideInTheSamePackageAsImplementation(..)` which will test that implementation and test class reside in the same package. The rule can e.g. detect mismatches like `com.myapp.correct.SomeClass` and `com.myapp.wrong.SomeClassTest`.

Resolves: #475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants