-
Notifications
You must be signed in to change notification settings - Fork 299
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
@ArchTest instance fields or static methods in abstract base classes #104
Comments
Honestly I was aware of this, while I implemented it, and yes, I was thinking "it will fail if a rule is declared in an abstract class, but then who would do that, if ArchUnit offers such nice ways of composition" 😉 |
BTW, is this a real problem for you (i.e. should I release a 0.9.2), or are you okay with the current state for now? You can avoid it by keeping the rules in the abstract base class static I think, can't you? |
…se class Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
… base class Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
…static methods) in abstract base class]} Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Keeping this open for JUnit 5 |
Thanks for merging the PR! ;) |
Naah, you were right that I took a shortcut, it's definitely more proper now 😉 |
You can also leave it as another excercise for me... 😉 |
If you want, go for it, I'd be happy 😉 But don't feel obliged, if it's too stressful I'll implement it at some point before 1.0.0... |
Are there plans to support placing |
Hmm, usually I don't think inheritance is such a great pattern to share configuration or logic. What I usually do, is to create a library via composition to run the tests, like
I would rather use your suggestion from #182 to encapsulate the details 😉 |
@codecholeric Hi if I can add an argument for the support of the |
As I said, I'm not totally against it, feels like it would be consistent behavior. It will just take a little time until I find the time to implement this, but if anyone wants to contribute this, I'd be more than happy to merge it 👍 |
@codecholeric The main issue with not supporting abstract base classes is that your example above using rule libraries makes it next to impossible to run a single test from the command line or in an IDE like IntellliJ. At least I have been unsuccessful there. Am I missing something? |
One big problem is, that IDEs like IntelliJ don't support to run a field as test, even if the JUnit Another option might be to add a quick marker annotation like
Which then would only run this one rule, even if multiple |
…se class Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
… base class Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
…static methods) in abstract base class]} Issue: #104 Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
…sses, we should separate the tests accordingly Issue: #104 Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
…lass So far, having `@ArchTest` fields or methods in an abstract base class would cause the JUnit 5 engine to crash. This also made the pattern to "share" tests via extending a common base class impossible, which some users would like to have. The change corresponds to the commits * 8188cdc * 625c3d6 * 59f8c4d which added the same feature for JUnit4 (Issue: #104). Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
So far, having `@ArchTest` fields or methods in an abstract base class would cause the JUnit 5 engine to crash. This also made the pattern to "share" tests via extending a common base class impossible, which some users would like to have. The change corresponds to the commits * 8188cdc * 625c3d6 * 59f8c4d which added the same feature for JUnit4 (Issue: #104). Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
#97 has removed the necessity to declare
@ArchTest
s as static fields or methods.archunit-junit4:0.9.1
however fails withon [
@ArchTest
(instance fields or non-static methods) in (a base class that cannot be instantiated itself, e.g. when the base class is abstract or does not have a default constructor)].Example:
The same holds true for
ArchRules.in
a class with such a base class.Even though such constellations can probably be avoided (we all favor composition over inheritance, don't we...?), ArchUnit should try to instantiate the correct class (
ArchTestWithAbstractBaseClass
instead ofAbstractBaseClass
in the example above).(Since I'm not experienced with Junit 5, I cannot judge yet whether
archunit-junit5
has similar issues.)The text was updated successfully, but these errors were encountered: