When you check if an exception has occurred, you will have to handle the exception in the unit test code. Right now, you are not doing this.
Here is an example: I have a method that reads in the file name and does some processing:
public void ReadCurveFile(string curveFileName) { if (curveFileName == null)
... etc. Now I am writing a test method to test this code as follows:
[Fact] public void TestReadCurveFile() { MyClass tbGenTest = new MyClass (); try { tbGenTest.ReadCurveFile(null); } catch (Exception ex) { Assert.True(ex is ArgumentNullException); } try { tbGenTest.ReadCurveFile(@"TestData\PCMTestFile2.csv"); } catch (Exception ex) { Assert.True(ex is ArgumentException); }
Your test should pass now!
source share