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
How to relax the rules for tests #1
Comments
Hi Jens, do you want to just disable all test rules for classes in |
Hi Johannes, I think both make sense.
|
Hi Jens, first of all, thanks for the feedback and asking the question :-) I've thought about this in the past, as well. Unfortunately, I haven't come up with the silver bullet for this. In the end, all the class file import knows, is the file URL of a class, which is in general not enough, to know if a class is test code. However, I did include a best guess for Maven and Gradle (as well as IntelliJ Idea). It uses the fact, that Maven compiles test classes to The ClassFileImporter allows to specify
This will simply exclude all URLs that contain '/test-classes/' or '/test/', which should leave exactly production code (except if you put your whole project in a folder called 'test', as I said, it's just a best guess). If this is not good enough, you can just implement So you can put your tests for test code and your tests for production code in two different test classes and use different import options. Is this good enough for your usecase? NOTE: I've just noticed, that I was a little sloppy on the implementation of DontIncludeTests.class and hardcoded the *nix file separator. This is fixed on master, but if you're developing on Windows, the provided ImportOption of version 0.4.0 will probably not work correctly. If so, you could just copy DontIncludeTests from https://github.com/TNG/ArchUnit/blob/master/archunit/src/main/java/com/tngtech/archunit/core/importer/ImportOption.java and use that for your tests. |
Hi Peter, thanks for your thoughts on this subject. I looked here: The ImportOption filters look promising. With |
Ok, I got it working. :-)
Two small suggestions:
|
Aaaaaaah, you're absolutely right, now I remember, I wasn't sloppy about the file separator, I though "thank God we're dealing with URIs here and don't have to worry about the file separator" *facepalm*. Anyway, glad to hear it works for you now :-) If you want to use Nevertheless, this got me thinking that the behavior could be more consistent. Thus from 0.5.0 on, I've also applied your suggestion, Since you say you got it working, I'll pull this change in and close this issue :-) |
ArchUnit is a great testing framework! I wonder whether there is a good way to relax the rules for classes under
/src/test/java
in a portable way.The text was updated successfully, but these errors were encountered: