Posts

Showing posts with the label mstest

Throw exception in test method using MSTest

Throw exception in test method using MSTest I'm using MSTest to write test cases for my application. I have a method where files are moved from one directory to another directory. Now when I run code coverage, it shows that the catch block is not covered in code coverage. This is my code as below. class Class1 { public virtual bool MoveFiles( string fileName) { bool retVal = false; try { string sourcePath = "PathSource"; string destinationPath = "DestPath"; if (Directory.Exists(sourcePath) && Directory.Exists(destinationPath)) { string finalPath = sourcePath + "\" + fileName ; if (Directory.Exists(finalPath)) { File.Move(finalPath, destinationPath); retVal = true; } } } ...