-
Notifications
You must be signed in to change notification settings - Fork 1
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
Circular dependencies in test suites #10
Comments
Hey @zhming0, Thanks for reporting! I wonder how you are scanning your namespaces? I try to keep For classpath scanning, (let [ns-names (->> (init.discovery/classpath-namespaces "company")
(remove #(str/ends-with? (name %) "-test")))]
(run! require ns-names)
(init.discovery/from-namespaces (map the-ns ns-names))) Another option is to keep I often also use a different name for the main namespace, e.g. Maybe that works for you as well? |
Thanks for the reply @ferdinand-beyer! I normally scan my namespaces via The option of keeping The last option of using difference name for main namespace doesn't seem to address the circular dependency either, So it sounds to me that option 1 is the only valid option and now the problem is whether it's a good idea to get |
I think this is the reason for your circular dependency. I normally don't do that, but instead write unit tests for components without spinning up a system. Since every component takes its dependencies as function arguments, this is quite straight-forward, and you can also pass test doubles as needed. Since you spin up a test system, I assume you have sort some of integration test, and I see the value of testing the system that is actually built. For test systems, you often might want to replace some components with test doubles as well. In your case a simple solution would be to put these tests in a different namespace, like You will still have a circular dependency if you scan for Having said all that, I think adding a way to customise scanning might indeed be useful... |
Added You can now do: (discovery/static-scan '[company] :exclude? #(str/ends-with? % "-test")) |
Thank you for taking care of this! Really appreciated! 🙇🏿 🙇🏿 |
Hmmm, for some reason that I don't understand yet, although Then I tried to simplify it:
I got compiler error instead: |
Argh, that's probably because of macro expansion... Since This will lead to: I forgot to Even then, we need to make sure that we actually find something, or |
@zhming0 -- can you try |
@ferdinand-beyer |
In Clojure, tests are conventionally located in
prefix.ns-test
, it post a small challenge in usinginit
. Because for example, if I useinit
to scan namespace prefixcompany
, it would normally auto require all test case namespaces to formsystem graph
, however, those integration test cases would normally need to import thesystem graph
, which results in circular dependencies.If I want to keep the clojure test namespace naming convention, there seems to be no good workaround for now. My current workaround leverage runtime
(resolve)
+kaocha
hooks, but it's a bit ugly.I wonder if it's worth to have a granular control when
init
do scan, perhaps, support filtering during scan? For example, we can allow pass in a filter function to filter out certain namespaces, such asxxxx-test
.The text was updated successfully, but these errors were encountered: