4

I am automating some test cases with Coded-UI And I am trying to figure out how to explicitly fail a test case from the code instead of waiting for the code to timeout. I considered creating an assertion that is bound for failure, but that feels sloppy to me. Here is an example of my code:

public bool CheckifFileExists(String SearchFile, int secondswait)
    {
        bool FileExists = File.Exists(SearchFile);
        int i = 0;
        while (FileExists == false && i <= secondswait)
        {
            FileExists = File.Exists(SearchFile);
            System.Threading.Thread.Sleep(1000);
            i++;
        }

        return (FileExists);
    }


bool FileExistsStatus = CheckifFileExists(SearchFile, secondswait);

if(FileExistsStaus == true)
    //continue test case
else
    //explicitly fail test case

I looked around for a while but could not find anything specific to Coded-UI that allows me to fail the test case.

Thank you!

4

1 回答 1

4

Moved from my comment on the question to an answer.

How about Assert.IsTrue(FileExistsStatus)?

于 2012-06-13T15:08:17.167 回答