Nunit 3.6.1 test with category: category not available in test context

I noticed that when using a test table instead of a test, the category of the test is not available through the test text. So let's look at some code:

[TestFixture]
public class FormTests : BrowserTests
{
    [TestCase("/some-url/", FormType.ContactForm), Category("form")]
    [TestCase("/some-other-url/", FormType.ContactForm), Category("form")]
    public void AssertFormIsSubmittable(string url, FormType formType)
    {
        Browser.OpenPage($"{BaseUrl}{url}", true);
        Browser.Action(FormActions.EnterFormFields(formType));
        Browser.Action(FormActions.Submit());

        var isSuccesfullySubmitted = Browser.Verify(FormState.IsSubmitted());
        Assert.IsTrue(isSuccesfullySubmitted);
    }

    [Test, Category("form")]
    public void FunctionToTestIfCategoryIsWorking()
    {
        Browser.OpenPage($"{BaseUrl}", true);
        Browser.Action(FormActions.EnterFormFields(FormType.ContactForm));
        Browser.Action(FormActions.Submit());

        var isSuccesfullySubmitted = Browser.Verify(FormState.IsSubmitted());
        Assert.IsTrue(isSuccesfullySubmitted);
    }
}

When running AssertFormIsSubmittable (with test windows) in the BrowserTests base class at runtime: the var category = TestContext.CurrentContext.Test.Properties.Get("Category");result is zero.

When I execute FunctionToTestIfCategoryIsWorking, the result is the same line of code. This is the expected result. One way or another, when using TestCase it no longer works.

I tried changing the attributes to:

[TestCase("/some-url/", FormType.ContactForm)]
[TestCase("/some-other-url/", FormType.ContactForm)]
[Category("form")]

and

[Category("form")]
[TestCase("/some-url/", FormType.ContactForm)]
[TestCase("/some-other-url/", FormType.ContactForm)]

and

[Test, Category("form")]
[TestCase("/some-url/", FormType.ContactForm)]
[TestCase("/some-other-url/", FormType.ContactForm)]

. , , . https://github.com/nunit/nunit, , .

Visual Studio 2015, 3 Windows 7 Enterprise. Nintit 3 Test Adapter Visual Studio.

-, ? , , :)

+4

Source: https://habr.com/ru/post/1673824/


All Articles