Fork me on GitHub
#polylith
<
2024-03-11
>
tlonist10:03:39

I have a question regarding poly test. Below is the recap of my situation. All tests are run using in memory h2 db (with mysql dialect). The configuration for h2 database including its init script is written in testing component, to which all other bricks refer in their own :test alias. Inside of every deftest that uses db, there is a function call to init function from testing component's interface. They work just fine when jacking-in to repl and running tests directly via run-tests. When run via poly test project:project_name , it succeeds at the very first time. The trials after complains about not being able to find the suitable driver and throws errors. I'm yet to understand how poly test works under the hood. can anyone shed some light on this problem?

furkan3ayraktar12:03:49

The first thing I can see from your explanation is that you mentioned bricks depend on another brick, testing, in their deps.edn. The most crucial rule in Polylith is that bricks do not depend on each other through deps.edn. They depend on interfaces, and which implementation will be included in the classpath will be decided at the project level. If you have a project named project_name, and if you want to use testing brick while testing that project, you can include the testing brick in the :test alias of the project_name project’s deps.edn. An example of this can be found in the Polylith repository. https://github.com/polyfy/polylith/blob/408ef27ecad00d3443120f2340fd0d95fa642535/projects/poly/deps.edn#L43, the poly project uses the test-helper brick while testing, and https://github.com/polyfy/polylith/blob/408ef27ecad00d3443120f2340fd0d95fa642535/components/creator/test/polylith/clj/core/creator/project_test.clj#L3 is an example of how the creator brick uses the test-helper. These two pages explain how testing works with Polylith: • https://cljdoc.org/d/polylith/clj-poly/0.2.19/doc/testinghttps://cljdoc.org/d/polylith/clj-poly/0.2.19/doc/test-runners Without seeing the entire setup and configuration, it’s hard to tell where the problem is. Since poly doesn’t do any magic, it always comes down to what you have in the classpath.

👍 1
seancorfield17:03:54

"not being able to find the suitable driver and throws errors" -- this sounds a bit like the classloader isolation problem with tests that some people have gotten around by switching to the external test runner (which uses process isolation instead).

👍 1
tlonist06:03:24

Problem solved! it all helped alot.