angular-test-patterns icon indicating copy to clipboard operation
angular-test-patterns copied to clipboard

New rule to organize unit test contents

Open daniellmb opened this issue 10 years ago • 6 comments

@yanivefraim I've always used comments to help organize the contents of a particular unit test such as:

// arrange
// act
// assert

or

// given
// when
// then

What do you think about adding a new rule to require similar comments within the test patterns?

daniellmb avatar May 06 '15 14:05 daniellmb

Sounds cool. Are those patterns always relevant?

yanivefraim avatar May 06 '15 19:05 yanivefraim

No, not always, for example, on some unit tests there may be nothing to arrange. But I don't think it's detrimental/distracting to have the comments there even if there is nothing in that part of the test. I find it is a nice future extension point when you do need to add code to arrange the unit test context, it is clear where that code should go.

daniellmb avatar May 07 '15 14:05 daniellmb

OK, I'm with you on this (:

yanivefraim avatar May 07 '15 14:05 yanivefraim

Do you have a preference between "arrange, act, assert" and "given, when, then"?

daniellmb avatar May 07 '15 15:05 daniellmb

I use "given, when, then", not sure what is better...

yanivefraim avatar May 08 '15 04:05 yanivefraim

OK, thanks, I don't have a strong preference. I typically use AAA, but GWT may fit a little better with the Jasmine BDD style.

daniellmb avatar May 08 '15 15:05 daniellmb