I'm trying to follow the Arrange-Act-Assert pattern when writing unit test and I got to a point where I'm confused on which approach will be better. I'm using xUnit and my first approach to the problem was:
//Arrange
int key = 1;
string value = "X";
//Act
board.Add(key, value);
var result = Assert.Throws<ArgumentException>(() => board.Add(key, value));
//Assert
Assert.IsType<ArgumentException>(result);
and my second approach is:
int key = 1;
string value = "X";
board.Add(key, value);
Assert.Throws<ArgumentException>(() => board.Add(key, value));
which is a better approach?
Edit: Blogged about this on wp.me/p4f69l-3z
I'd say your second example is better. Assert.Throws will pass/fail the test so there's no reason to get it's result and assert on that. When I'm writing 'will throw' tests I keep it on one or two lines: