VSFF*: XUnit and related

VSFF* – Visual Studio Full Fat. Just to make an obvious distinction with VSCode.


XUnit: testing for exceptions

I think I’ve written about this before… but I can’t find it. Basically I find the paradigm for exception testing nicer in XUnit compared with MsTest, in my view. Note that there is no decoration, and you can test easily both for the exception type, and for a message (in this case) that accompanies it:

public void RequestForNotFoundFrequencyThrowsException() {
var toneSet = new Model.ToneUtility();
Exception ex = Assert.Throws<ArgumentException>(() => toneSet.GetNoteElements(9999));
Assert.Equal("[The frequency [9999] was not found in the set of available notes]", ex.Message);