Open GoogleCodeExporter opened 8 years ago
That's actually kind of a feature. What happens is that at construction time,
the only code that isn't actually executed is the body of the tests themselves
which are demarcated by:
"do some behavior" in { ... }
Everything surrounding that is executed at construction time so that all tests
can be registered at construction time. This enables the total number of
expected tests to be known prior to run being invoked, which in turn means a
GUI can put up a nice progress bar (we know how many tests are expected, so we
can tell how far we got). If there are any side effects at the top level, or in
a scope ("should" or "when" clauses) in a WordSpec, you'll see them at
construction time. If you mix in OneInstancePerTest, you'll see those side
effects once per test.
Best practice is to move the side effects into something like a withFixture or
before/after, etc. Another thing to look at is org.scalatest.path.FreeSpec or
org.scalatest.path.FunSpec. (There's no path.WordSpec, because the words are in
the wrong places English-wise.) The path traits do execute just the path to the
test each time, for the purpose of eliminating unnecessary side effects that
are not in the "path" to the test.
Original comment by b...@artima.com
on 14 Jun 2013 at 12:31
That you for clarifying this. I will experiment with the path specs to see if
they fit my needs. Feel free to close this issue.
Original comment by richardw...@googlemail.com
on 19 Jun 2013 at 11:54
Original issue reported on code.google.com by
richardw...@googlemail.com
on 14 Jun 2013 at 8:57