2008 Advent Calendar December 3rd




1: public class Advent3
2: {
3: [Fact]
4: public void TestRead()
5: {
6: // Create a test file
7: IFileUtil file = new FileUtil(“SomeFile.txt”);
8: file.Create(“CONTENT”);
9:  
10: // Should be able to read file
11: Assert.DoesNotThrow(() => { file.Read(); });
12:  
13: file.Readable = false;
14:  
15: // Should NOT be able to read file.
16: Assert.Throws<AccessViolationException>(() => { file.Read(); });
17:  
18: // Clean up
19: file.Delete();
20: }
21: }

Using XUnit.net asserts to verify exceptions is much better than what we did yesterday. Now the test starts to be small enough to be understood easily. But I think there is a major problem with this test. We’re not only testing that we cannot read an unreadable file, I’m also verifying that I can read a readable file. I think this should be split up into two different tests and that is what will happen next.

Comments (0)