5

I'm trying to run some tests to check my postfix bitwise algorithm with XUnit. It seemed like a [Theory] with [InlineData] would work perfectly for this, but it does not appear to be working like I was hoping.

    [Theory]
    // a && b
    [InlineData(new object[] { false, false, BitwiseOperator.And }, false)]
    [InlineData(new object[] { true, false, BitwiseOperator.And }, false)]
    [InlineData(new object[] { false, true, BitwiseOperator.And }, false)]
    [InlineData(new object[] { true, true, BitwiseOperator.And }, true)]
    public void Test(IEnumerable<object> tokenPrimitives, bool expectedResult)
    {
        //Run test
    }

When the the NCrunch test runner (or does this use Visual Studio test runner?) scans for tests, it only picks out two tests from the four [InlineData]. It always seems to be one with expectedResult = false and one with expectedResult = true. At a glance, it seems as if the scanner is treating all tests with expectedResult = false as being equal, and thus ignoring the other two.

So my question is: can I use [InlineData] for this, and if so how? Otherwise I am open to ideas. I've been trying to experiment with [MemberData], but I've had similar frustrations. It appears to run all my tests, but the console only displays one test instead of 4, which makes it difficult to figure out which test fails. I've found a solution to this in a different Stackoverflow question, but I've yet to get it to work for this scenario.

Andy Clark
  • 516
  • 1
  • 4
  • 21
  • Having the same problem. Did you find a solution for this? – Carlo Jun 05 '18 at 23:51
  • same problem, there seems to be a bug in the runner. i added an fake "id" parameter with unique value for each inline (1, 2, 3, 4, etc). then the runner identifies they are different. – Fabio Marreco Nov 30 '18 at 13:06
  • I had the same problem today, it seems like it's not working with enum values. I had to cast them to int to make the test get recognized & work. I read something about the test project not correctly referencing the tested project but I could not resolve it until now. – IngoB May 25 '19 at 16:49

0 Answers0