2

I would like to use Catch to do unit testing on a C++ lib. However I need the most of the test cases to be run in an order. ie the library needs to be init in a certain way and then users logged in etc. Is there any design pattern for achieving this.

Thank in advance.

Darren Cook
  • 27,837
  • 13
  • 117
  • 217

1 Answers1

5

Tests are run sequentially, just as you describe. So the simple answer is you do not have to do anything to get this functionality.

However super-long test functions, with a mix of fixture creation and asserts are considered bad form when unit testing: they become harder to maintain, and it takes longer to isolate the problem. The Catch way of tackling this issue is rather interesting, see the tutorial on Sections; I also found this presentation (video, 67 mins) by Phil Nash, where (from about 20:00 to 28:00) he explains quite clearly how sections and nested sections work.

Darren Cook
  • 27,837
  • 13
  • 117
  • 217