microsoft / testfx

MSTest framework and adapter
MIT License
780 stars 259 forks source link

How to ignore particular test case (DataRow) #1043

Open ashahabov opened 2 years ago

ashahabov commented 2 years ago

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

ashahabov commented 2 years ago

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.

Evangelink commented 1 year ago

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?

ashahabov commented 1 year ago

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.

Evangelink commented 1 year ago

@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.

tymtam2 commented 1 year ago

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.

Evangelink commented 1 year ago

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

BennCowenRT commented 1 year ago

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.

TobiasGPersson commented 9 months ago

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.

Evangelink commented 9 months ago

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.