Skip to main content

Assertions

As in any other codebase, it is good practice to assert assumptions before continuing with more heavy procedures in your build automation. When an assertion is violated, it usually entails that the build should fail immediately.

In the most simple form, you can fail a build by calling:

Assert.Fail("This was unexpected!");

Furthermore, you can use one of the following more specific assertion methods:

// Assert not-null fluently
obj.NotNull().ToString();

// Assert not-null explicitly
Assert.NotNull(obj);
info

Each of the above methods uses the CallerArgumentExpressionAttribute to capture usage details from the call-site. If you want to provide a more comprehensive explanation, you can pass the message parameter instead.