code-pal-for-abap icon indicating copy to clipboard operation
code-pal-for-abap copied to clipboard

GivenWhenThen for Test Methods

Open lucasborin opened this issue 4 years ago • 2 comments

Based on Use given-when-then, can we have a Check recommending the test method to follow the GivenWhenThen style?

The check could scan for given, when, and then keywords in comments and methods within a test method.

Further Reference: GivenWhenThen by Martin Fowler

lucasborin avatar Apr 09 '21 19:04 lucasborin

given can be empty. For instance, when you test an exception.

lucasborin avatar Apr 09 '21 19:04 lucasborin

Not in favour of this one. Firstly, although I broadly follow the pattern, it is often sensible to combine two of the stages or even all of them, e.g. cl_abap_unit_assert=>assert_initial( cut->meth( ) )..

Secondly, tests should also be simple and readable and put technicalities into helper classes. As such I feel it is unnecessary clutter to add comments to every two- or three line test.

Personally I subscribe to the idea that unit tests should document the code and like to make use of helper methods to keep tests as simple and readable as possible, see https://blogs.sap.com/2019/04/04/writing-simple-readable-unit-tests/ given-when-then comments would not add any value here.

pokrakam avatar Sep 16 '21 15:09 pokrakam