DEV Community

Discussion on: Help me improve my unit tests

Collapse
 
alainvanhout profile image
Alain Van Hout
  1. I personally, and the team I'm part of, also inherently follow the AAA pattern, but tend to use simple whitespace delineation rather than repeating the same comments in every test.
  2. Unit tests and integration tests are always given separate namespaces (packages, since we use Java).
  3. We always try to use method names of the form 'methodOrConcern_shouldSomeEffect_whenSomeCause', though we tend to allow for varations in the order of the should and when, and allow 'if' versus 'when' depending on what seems more appropriate in the specific circumstances.
  4. Testing, just like all of programming, is a matter of growing and evolving, which we tend to do as a team. As such, seniors advise juniors, but juniors also offer alternative opinions and suggestions, and in the end everyone learns :).
Collapse
 
meanin profile image
Paweł Ruciński

Hi, thanks for reply.

Referencing to point 1, I am aware of empty spacer approach. Still, I think, that it is easier to involve someone into TDD without any skills, when there is clear distinction between each section.

Collapse
 
alainvanhout profile image
Alain Van Hout

Fair enough. Within the context of a training exercise that's definitely an important factor. I was mostly talking about 'production code', where superfluous comments tend to decrease the signal-to-noise ratio (if ever so slightly).

That said, I strongly believe in the ability of (appropriately short) comments to add contextual information and remove potential misunderstanding, thereby increasing maintainability. And in the context of training, the AAA comments are exactly that.

Thread Thread
 
meanin profile image
Paweł Ruciński

Thanks again, I will keep that in my mind.

Very good point!