In JUnit
, I want to develop a framework that will intercept test method, say testA
and will call before it a method beforeA()
and call afterA()
after. I want to use it to prepare data before and destruct it after the test run.
I cannot use regular @before
and @after
because they run before and after all tests. And I also do not want to divide the original test class to small tests.
Is this legitimate or this is not good because we are running test preparation and destruction inside the JUnit test method (and not in the before/after)?
I believe it is ok since in any event if I fail a test I should use assert
(Test Failure) and not regular exception
(Error/Exception) so it should not make a difference where exactly the test failed/exceptioned as long as I assert on test failure.
What do you think?