Skip to content
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

Refactoring proposal: Reorder tests #240

Open
turion opened this issue Jan 10, 2023 · 0 comments
Open

Refactoring proposal: Reorder tests #240

turion opened this issue Jan 10, 2023 · 0 comments

Comments

@turion
Copy link
Collaborator

turion commented Jan 10, 2023

Right now the structure of tests is:

  • One big Spec.hs file that contains half of every test
  • Flat collection of modules TestFoo.hs that contain the other half of the tests, but sorted by topic

For example we have in Spec.hs:

  describe "Population" do
    context "controlling population" do
      it "preserves the population when not explicitly altered" do
        popSize <- TestPopulation.popSize
        popSize `shouldBe` 5

And in TestPopulation.hs:

popSize :: IO Int
popSize =
  sampleIOfixed (weightedSampleSize $ spawn 5 >> sprinkler)

To understand whether the test is correct, and also to write a new test, I need to deal with both files and keep them in sync. Also, Spec.hs will grow longer and longer to the point where one has to jump around a lot in the file to search for (halves of) tests.

Proposal

How about refactoring like this:

  • Move TestFoo.hs -> Test/Foo.hs
  • Test/Foo.hs tests exactly functions from src/Control/Monad/Bayes/Foo.hs
  • All tests regarding one module are collected in one describe "Foo" block
  • There is a root file Test.hs importing and collecting all those individual tests in one hspec block
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant