0

I am trying to add a message when I try to skip a test case my condition statement. I am able to skip without adding a message. But I would like to add a message for the reason to skip it. But Nunit never displays the message.

if (...)
{
  Assert.Ignore("Data not found.");
}

What should be the solution to add the message while skipping my test case?

user1413
  • 527
  • 4
  • 21
  • What do you mean it does not display the message? Visual Studio? Command line? Which test runner/adapter are you using? What test runner are you using? Side note: According to http://nunit.org/docs/2.6/utilityAsserts.html, sounds like Assert.Inconclusive(string message, object[] params) might be more suited for your use case. – Alexandru Clonțea Sep 05 '18 at 19:25
  • @AlexandruClonțea Nunit UI Test Runner Chech my Image. And Let me know if you need any other details https://s33.postimg.cc/rt6bh6bhb/9-5-2018_3-34-33_PM.jpg – user1413 Sep 05 '18 at 19:37
  • @AlexandruClonțea I know we have below syntaxs. And I tried with first one but C# is actually using `public static void Ignore();` this one. I have no idea what should i pass in `params object[] args` if I have to use last one. If you have any example let me know. From Assert.cs file `public static void Ignore(string message);` `public static void Ignore(string message, params object[] args);` – user1413 Sep 05 '18 at 19:46
  • Think of the (string message,params object[] argss) part as short for string.Format(string message, params object[] args) (i.e. string.Format("{0}, {1}", object1, object2)... Archaic remains of the old times of having no string interpolation. I have no idea why your GUI is not displaying the message. – Alexandru Clonțea Sep 05 '18 at 19:56

1 Answers1

1

There are a lot of ways to alter the results of the test, here are some of many. And ways you can view different test result statuses

            TestExecutionContext.CurrentContext.CurrentTest.MakeInvalid("I want this test to be SKIPPED");
                    ResultState resultStateObject = new ResultState(TestStatus.Skipped);
                    TestExecutionContext.CurrentContext.CurrentResult.SetResult(resultStateObject, "this test is being skipped derp derp");
                    TestExecutionContext.CurrentContext.CurrentTest.RunState = RunState.Ignored;
                    Logger.log("After doing things");
                    resultstate = TestExecutionContext.CurrentContext.CurrentResult.ResultState.ToString();
                    Logger.log("%%%%%%%%%%%%%%%%%% Result State: " + resultstate);
                    resultstatestatus = TestExecutionContext.CurrentContext.CurrentResult.ResultState.Status.ToString();
                    Logger.log("%%%%%%%%%%%%%%%%%% Result State Status: " + resultstate);
                    runstate = TestExecutionContext.CurrentContext.CurrentTest.RunState.ToString();
                    Logger.log("%%%%%%%%%%%%%%%%%% Run State: " + runstate); //test="@runstate = 'Skipped' or @runstate = 'Ignored' or @runstate='Inconclusive'
                    status = TestContext.CurrentContext.Result.Outcome.Status.ToString();
                    Logger.log("%%%%%%%%%%%%%%%%%% Result Status: " + status);
                    message = TestExecutionContext.CurrentContext.CurrentResult.Message.ToString();
                    Logger.log("%%%%%%%%%%%%%%%%%% Message: " + message);
Shannon McRae
  • 231
  • 3
  • 10
  • 1
    Thanks. But yes I ended using Logger.log. I think with new version of Selenium `Assert.Ignore` is not available. That is why I was not able to use it. I had uploaded 2 years ago but impressive you found my post. Appreciate your reply as well – user1413 Nov 17 '22 at 05:30