Fork me on GitHub

How do folk approach writing tests for fns that require entire whole systems or components that require more dependencies than is easy to do manually?


I feel like I keep writing stuff of the form:


(deftest test-foo
      (let [system (component/start-system (build-test-system (build-test-config)))]
       (finally (component/stop-system system))))


with varying amounts of decoration applied to the config or the system in the setup phase


I’m nearly ready to reach for a macro, but it occurs to me to question my design approach first


@donaldball: for my integration tests I have setup a test system that I start and stop before / after each test with (use-fixtures :each.... Also, my system has a config component that is adapted to the test system. If you have different configs for different tests, either put them in different namespaces, or make the function calling the system take a config parameter.


@donaldball: that's a pretty common approach. You can assoc/dissoc parts of the system before component/start to add/remove specific components for a test. See also for suggestions on reducing the overhead of setup/teardown for tests.