0

There is a question-discussion about having unit tests without assertions. But there is also another question which might need some discussion:

Is it a good practice to have non-test method(s) having assertions in xUnit or Integration test class, which is(are) used in test methods inside the same or other test classes?

EDIT: How to implement a case, when you have several test cases which are required to run in a specific order and running in that order those multiple test cases construct another test case? Is it good to implement those test cases as non-test methods with assertions and then have one test method which calls all these chained methods in an order?

Community
  • 1
  • 1
Armine
  • 1,675
  • 2
  • 24
  • 40
  • Yes, it can be. DRY - don't repeat yourself. If you can factor out common code used by multiple tests into re-usable chunks, it will usually decrease your cost of development and maintenance. – Andy Thomas Apr 27 '17 at 16:42
  • @AndyThomas even if it contains (multiple) assertions? – Armine Apr 27 '17 at 16:44
  • Yes, even if it contains one or more test assertions. For example, you might have different tests for different data -- but apply the same assertions regardless. – Andy Thomas Apr 27 '17 at 16:49
  • @AndyThomas could you please take a look on my edit also? Thanks a lot. – Armine Apr 27 '17 at 17:02
  • That's a separate question worthy of posting separately, after first searching for duplicates. The answer may depend partly on your unit test framework, so be sure to specify that. In general, the answer will be NO -- ideally, you want minimal unit tests, that test one thing, and will be reported separately in the unit test results. It's a lot more informative to see that *testFooWithUpperBoundBelowRange()* failed, than seeing in the report that *doAllMyTests()* failed. – Andy Thomas Apr 27 '17 at 17:15

0 Answers0