M
M
Melz2019-05-04 20:52:32
C++ / C#
Melz, 2019-05-04 20:52:32

What is the best way to set the Inconclusive status if the component does not exist?

Hello,
There is a small problem in that you need to test data from a piece of iron.
The piece of iron is not always connected to the computer and not everyone has it and in fact not everyone needs it.
Desire - so that if it is not there, the tests do not fall, but give Inconclusive .
Actually googled only such a solution with a base class.
In the base class, a connection test and cleanup after that. If the test fails, nothing is tested in the inherited one and shows Inconclusive. The base class should not be visible in the Test Explorer.
Are there better options?

[TestFixture]
    public class TestClassInheritanceBase
    {
        private bool _isConnected;


        [SetUp]
        public void BaseSetUp()
        {
            _isConnected = false;
            Debug.WriteLine("base. SetUp");
        }

        [SetUp]
        public void BaseTearDown()
        {
            Debug.WriteLine("Base. SetUp");
        }
        
        public void TestIsConnected()
        {
            if (!_isConnected)
            {
                Assert.Inconclusive("Device missing.");
            }
        }
    }

    [TestFixture]
    public class TestClassInheritance: TestClassInheritanceBase
    {

        [SetUp]
        public void SetUp()
        {
            Debug.WriteLine("SetUp");   
        }

        [SetUp]
        public void TearDown()
        {
            Debug.WriteLine("SetUp");
        }


        [Test]
        public void TestMethod()
        {
            TestIsConnected();
            var answer = 42;
            Assert.That(answer, Is.EqualTo(42), "Some useful error message");
        }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-05-05
@melz

In order for TestClassInheritanceBase not to be shown in the list of tests, it is enough not to put the TestFixture attribute on it.
And it looks like the BaseTearDown and TearDown methods should have the TearDown attribute, not SetUp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question