testfx icon indicating copy to clipboard operation
testfx copied to clipboard

How to ignore particular test case (DataRow)

Open ashahabov opened this issue 3 years ago • 9 comments

Description

I am trying to ignore one test case by adding Ignore keyword for DataRow attribute:

[TestClass]
public class MathTests
{
    [TestMethod]
    [DataRow(1, 1, 2)]
    [DataRow(2, 2, 3), Ignore]
    public void Sum_Test(int a, int b, int expectedSum)
    {
        var sut = new Math();
        
        var sum = sut.Sum(a, b);
        
        Assert.IsTrue(sum == expectedSum);
    }
}

public class Math
{
    public int Sum(int a, int b)
    {
        return a + b;
    }
}

but it ignores the whole test:

image

I also asked this on StackOverflow: How to ignore particular test case in MSTest.

Expected behavior

Only Sum_Test(2,2,3) test case should be ignored.

Actual behavior

It ignores both test cases.

Environment

  • Operating system: Windows 10 Pro
  • Target: .NET 6
  • MSTest.TestFramework: v2.2.8

ashahabov avatar Feb 13 '22 08:02 ashahabov

Looks like there is no such option. The most appropriate option is just comment DataRow statement.

However, would be good to have something like this [SkipDataRow("because this edge case is postponed", 2, 2, 3)], thus enabling to specify ignore reason.

ashahabov avatar Feb 19 '22 15:02 ashahabov

Hi @adamshakhabov,

I'd like to understand why you would prefer to have a property/different attribute... to skip a DataRow instead of simply commenting it out? Are you interested in building some analyzer or tracking number of skipped tests?

Evangelink avatar Jan 23 '23 11:01 Evangelink

Hello @Evangelink,

thank you for the reply🙂

"DataRow" is a piece of code. Commenting on code is not allowed in our team. I believe it is not a rare case. And yes, in the test result, I would like to have an opportunity to track the number of test cases that were skipped.

ashahabov avatar Jan 27 '23 19:01 ashahabov

@adamshakhabov it perfectly makes sense and you are not the only team with such rule. I just wanted to confirm the intent so we could think about how to implement it.

Evangelink avatar Jan 28 '23 07:01 Evangelink

My case is that I have tests that take a long time (>2 mins) I would like them to not run by default but I would like to be able to run them sometimes without having to change the code.

tymtam2 avatar Feb 04 '23 00:02 tymtam2

@tymtam2 Thanks. I would probably recommend for your case to have different tests and use categories to split tests you want to run.

Evangelink avatar Feb 06 '23 09:02 Evangelink

We have failing test cases we'd like to ignore with messages indicating ticket number for resolution of the issues. We'd like to ignore rather than comment to maintain visibility of them in our test reporting.

BennCowenRT avatar Apr 20 '23 23:04 BennCowenRT

Any updates on this issue? We're having temporary problems with an integrationtest where some datarows will fail due to problems within the called api. While we're waiting for a hotfix on the api-side, we would like to keep these datarows "alive" with the Ignore-attribute in order to fix them later. Commenting them out will increase the risk to forget about them even when the hotfix is pushed.

TobiasGPersson avatar Feb 13 '24 17:02 TobiasGPersson

Hi @TobiasGPersson,

This is something we are considering for future but we had to prioritize features based on upvotes and criticity for our customers so sadly this wasn't picked yet.

If we have some room left, I will try to fit it in the stretch goal of 3.3.

Evangelink avatar Feb 13 '24 19:02 Evangelink