1

I have a pack of smoke test that run and randomly pull data from a table and search by that data in another method and assert after. The test will fail if no data exist. I have a reusable method called RandomVinSelect(). I want to stop the test if there is no data. I have searched for test result warnings that test could not be ran instead of failing the test. At this point I am stumped. This is the code I have I do not want to run the lines after UI.RandomVINSelect if no data found. I am thinking there may not be a way for this using Xunit and it would just be pass or fail...

    public static string RandomVinSelect(this Browser ui, string table, 
    string selector)
    {
        //I want to stop test here if no data exist or create a dataexist 
        //method that stops a test.
        int rows = ui.GetMultiple(table).Count;
        Random num = new Random();
        string randomnum = Convert.ToString(num.Next(1, rows));
        string newselector = selector.Replace("1", randomnum);
        string vin = ui.Get(newselector).Text;
        return vin;
    }
rowdog_14
  • 31
  • 7
  • Nunit has an Inconclusive result, but I can’t see anything similar for Xunit.. http://nunit.org/docs/2.6/utilityAsserts.html – Scott Newson Jan 10 '18 at 14:37
  • 1
    Thanks, yeah I saw the Assert.Inconclusive for nunit :(. I am not finding anything with xunit either :( – rowdog_14 Jan 10 '18 at 14:50

2 Answers2

0

Perhaps just put smoke tests in a separate test package or collection and include a test that just checks to see if it can get data, then when you run this group of tests if that first test fails you know it is just due to no data being available.

Not ideal but might be good enough?

Scott Newson
  • 2,745
  • 2
  • 24
  • 26
  • ok thanks, I think I found something https://stackoverflow.com/questions/34610133/xunit-equivelant-of-mstests-assert-inconclusive – rowdog_14 Jan 10 '18 at 15:28
0

I installed the new nuget package(xunit.SkippableFact) added [SkippableFact] to my smoke test. Then I created a method that can be called to check and see if data is available and runs a Skip.If(condition,"my message") within that method and closes the test early if no data is present. Then in the Test Explorer show a warning symbol.

    public static void IsDataAvaiable(this Browser ui)
    {
        bool data = true;
        string pagecount = ui.GetPageCount();
        if (pagecount == "0") data = false;
        Skip.If(data == false, "The test could not run because no data available for validation.");
    }
rowdog_14
  • 31
  • 7