Posts Tagged ‘assert’

Write (arrange) Act and Assert in your automatic tests

November 14th, 2020

It is a good custom to write out Act and Assert in test as it helps to write the test in a clean way; and helps the next reader to understand where Arrange stops and Act begins. It helps the writer to not involuntarily write Act statements in Assert.
Like so:

myTest()
sut = setup()

// Act.
sut.do()

// Assert.
assert(sut.value).equals(12)

The above code is too simple to make the upside of this coding standard visible but soon tests get a few lines long and commentning Act and Assert is a good idea.

I don’t bother to write out // Arrange any more as all tests start with Arrange anyway.

Well… that was not true. I have stumbled upon tests with several Arrange, Act and Assert in them. Typically for integration tests.