Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 6
    What if the tests need some rather complicated setup? Sometimes these sort of things are not under your control. Commented Oct 12, 2010 at 23:38
  • Well, I'm guessing the complicated setup are "initial condition" of the tests. If that fails, all your tests should fail. In fact, I'm working on such a project right now, and people who never used unit tests constantly asked the same thing..until we explained what unit tests really are :) Then they realized it can be done, in spite of tremendous complexity of the project. Commented Oct 13, 2010 at 7:21
  • 1
    What's the best way to check that this "initial condition" is met is exactly the point of my question. Do you write a separate test for that? Or just assume that the tests will break if this condition is not true? What about the situation when the setup is not "catastrophically" bad, just slightly off? Commented Oct 13, 2010 at 14:52
  • 2
    Your tests should fail if the initial conditions are not right, that's the whole point. When in state A, you expect result B. If you don't have state A, a test should fail. At that point you can investigate why it failed, bad initial conditions or a bad test, but it should fail in both cases. Even if it is, as you say, "slightly off" (i.e. "A" => "B", "a" => "b", but never "a" => "B" or your test is bad). Commented Oct 13, 2010 at 15:38