seratch / scalatest

Automatically exported from code.google.com/p/scalatest
Apache License 2.0
0 stars 0 forks source link

BeforeAndAfterEach should have onError hooks #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
There are some use cases where it would be useful to be notified that an error 
occurred during test execution. I'd like to have an onError() hook method 
similar to beforeEach() and afterEach() that gets called in the catch {} clause.

Thanks :)

Original issue reported on code.google.com by shai.yal...@gmail.com on 30 Dec 2012 at 1:03

GoogleCodeExporter commented 8 years ago
This sounds like it may be more a job for withFixture rather than 
BeforeAndAfterEach, but I'd like to know more about your use case. Can you 
describe in more detail what you'd like to accomplish with the onError 
information?

Original comment by b...@artima.com on 31 Dec 2012 at 5:25

GoogleCodeExporter commented 8 years ago
We have a specialized log appender for testing purposes that buffers all log 
events and only writes them to stdout when a test fails, this helps keep the 
build log clean unless something breaks.

Original comment by shai.yal...@gmail.com on 31 Dec 2012 at 7:46

GoogleCodeExporter commented 8 years ago
Sounds reasonable, but does sound like a good use case for overriding 
withFixture. Are you aware of withFixture? If so, is there some reason you want 
to use BeforeAndAfterEach instead? If not, you can read up on it here:

http://www.artima.com/docs-scalatest-2.0.M5/org/scalatest/FlatSpec.html#withFixt
ureNoArgTest

And here:

http://www.artima.com/docs-scalatest-2.0.M5/org/scalatest/FlatSpec.html#withFixt
ureOneArgTest

If the test function results in an exception, that's a failed test. You can 
catch it, write to the log, then rethrow it.

Original comment by b...@artima.com on 31 Dec 2012 at 7:55

GoogleCodeExporter commented 8 years ago
Fair enough. I just thought it might be useful to have a hook method for that :)

Original comment by shai.yal...@gmail.com on 31 Dec 2012 at 9:28