re: GIVEN my article WHEN a reader reads it THEN the reader writes better tests VIEW POST

re: I like the idea of given/when/then but I don’t like to use it in Java JUnit e.g. because it’s not support as semantic or syntactic part of the test...

This, like many things requires buy in from your team; otherwise, as you say, the comments will be obsolete quickly.

You need to be able to trust that your team will check for things like this in code review so that you can avoid the exact situation you described. If there isn't that trust then this will probably become more of a distraction and hinderance.

It's worth saying though, since the tests test behaviour, the comments shouldn't change that frequently otherwise your system behaviour is changing which will probably then be breaking backwards compatibility. Sure the exact lines of code may change with a refactor etc. but the behaviour described in the comments should ordinarily be static, and if not then obvious how they should be changing buy the commit message etc.

code of conduct - report abuse