NSherwin
NSherwin

Reputation: 184

Do tests belong in-tree alongside the code, or in a serarate test-tree?

When designing a new testing system, Should I keep tests in tree with the source-code, for example, in a test sub-directory of the application root. Therefore running the tests for a given branch of your code only against that branch.

OR

Should I keep a separate source tree for the tests, and run the latest tests against all branches of the project?

Upvotes: 1

Views: 254

Answers (3)

xs0
xs0

Reputation: 2897

I think keeping them with the source code is better. It's often the case that expected behavior for a given piece of code changes, and the tests then change as well. Also, as you add functionality, you will get new tests that would fail on older code.

That said, it makes good sense to have tests in a separate directory of your source repository, so you can easily get rid of them when releasing. But they should be versioned together with the code they're testing, in any case.

Upvotes: 0

Jon Reid
Jon Reid

Reputation: 20980

I do it both ways. It depends:

  • If the system under test is distributed as binary, I keep tests next to the code. I prefer this because it makes it easier to switch between tests and source. It also increases the visibility of tests to other developers, especially those who aren't yet writing their own tests.
  • However, if the system under test is distributed as source code, I keep tests in a parallel tree so that people can choose to get the working system only.

Upvotes: 0

Alan
Alan

Reputation: 1045

Our team, and most teams where I work put unit tests in the same tree as the code, but put the rest of the tests (aka the tests the test team writes) in a separate tree. Organizationally, the test tree mirrors the code tree (i.e. the directory structure is the same (mostly)).

But we write a lot of test code.

Upvotes: 1

Related Questions