Is it possible to execute a method before and after all tests in the assembly?

If all your test fixtures are within the same namespace then you can use the [SetUpFixture] attribute to mark a class as the global setup and teardown. You can then put all your login/logout functionality in there.

NUNIT 2.x

namespace MyNamespace.Tests
{
    using System;
    using NUnit.Framework;

    [SetUpFixture]
    public class TestsSetupClass
    {
        [SetUp]
        public void GlobalSetup()
        {
            // Do login here.
        }

        [TearDown]
        public void GlobalTeardown()
        {
            // Do logout here
        }
    }
}

See:
http://www.nunit.org/index.php?p=setupFixture&r=2.4

NUNIT 3.x

namespace MyNamespace.Tests
{
    using System;
    using NUnit.Framework;

    [SetUpFixture]
    public class TestsSetupClass
    {
        [OneTimeSetUp]
        public void GlobalSetup()
        {
            // Do login here.
        }

        [OneTimeTearDown]
        public void GlobalTeardown()
        {
            // Do logout here
        }
    }
}

See:
https://github.com/nunit/docs/wiki/SetUpFixture-Attribute

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)