question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Data-driven tests are not fully supported for overloaded test methods

See original GitHub issue

Description

The MSTest V2 test framework does not appear to correctly support overloaded data-driven test methods. Only tests for the first overload are actually found and executed.

Steps to reproduce

Compile and execute the unit tests in the following code fragment:

using System.Globalization;

namespace TestProject1
{
    [TestClass]
    public class UnitTest1
    {
        [DataTestMethod]
        [DynamicData(nameof(Equal_StringAndInt32), DynamicDataSourceType.Method)]
        public void Equal(string x, int y)
        {
            Assert.AreEqual(x, y.ToString(CultureInfo.InvariantCulture));
        }

        [DataTestMethod]
        [DynamicData(nameof(Equal_Int32AndString), DynamicDataSourceType.Method)]
        public void Equal(int x, string y)
        {
            Assert.AreEqual(x.ToString(CultureInfo.InvariantCulture), y);
        }

        private static IEnumerable<object[]> Equal_StringAndInt32()
        {
            yield return new object[] {"1", 1};
            yield return new object[] {"2", 1};
        }

        private static IEnumerable<object[]> Equal_Int32AndString()
        {
            yield return new object[] {1, "0"};
            yield return new object[] {2, "2"};
        }
    }
}

Expected behavior

The test results in both Visual Studio and the console runner report 4 tests: two for the Equal(int x, string x) overload and two for the Equal(string x, int x) overload. For each of these overloads, one test should pass, and one should fail.

Actual behavior

Only the results for the Equal(int x, string x) overload are reported in Test Explorer:

image

Running dotnet test -t --nologo --no-restore --no-build also finds only two tests:

Test run for TestProject1.dll (.NETCoreApp,Version=v6.0)
The following Tests are available:
    Equal (1,1)
    Equal (2,1)

Running dotnet test --nologo --no-restore --no-build only executes two tests:

Test run for TestProject1.dll (.NETCoreApp,Version=v6.0)
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
  Failed Equal (2,1) [13 ms]
  Error Message:
   Assert.AreEqual failed. Expected:<2>. Actual:<1>.
  Stack Trace:
     at TestProject1.UnitTest1.Equal(String x, Int32 y) in C:\Users\exg906\source\repos\TestProject1\UnitTest1.cs:line 12


Failed!  - Failed:     1, Passed:     1, Skipped:     0, Total:     2, Duration: 32 ms - TestProject1.dll (net6.0)

Environment

  • Operating system: Windows 10
  • MSTest framework and adapter: v2.2.10
  • Visual Studio Enterprise 2022 (17.3.3)
  • Target framework: .NET 6.0
  • Test Execution Command Line Tool: v17.3.0
  • Microsoft.NET.Test.Sdk: v17.3.1

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Evangelinkcommented, Nov 25, 2022

Awesome, I’ll get back to you early next week (or during weekend) with where you could start!

1reaction
driesengcommented, Nov 25, 2022

@Evangelink: sure, I’d be happy to help.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data-driven unit tests for managed code
In this article, I will show how you can define test data using all these types of source and execute unit testing methods...
Read more >
Data Driven Testing - Windows drivers
Data Driven Testing is great for testing areas that work with a set of input values that define their behavior - for example,...
Read more >
How to test overloaded method using spock "where" table
Anyway, one workaround for the Spock bug I was just linking to is to not call the method with the null parameter from...
Read more >
Tutorial: Spock Part 3 - Data Driven Testing
Tutorial: Spock Part 3 – Data Driven Testing ... Firstly, Groovy supports operator overloading, so the left-shift operator ( << ) here means ......
Read more >
Data Driven Testing: A Comprehensive Guide With ...
Data -driven testing in manual testing is a technique where test cases are designed to use external data sources, such as spreadsheets or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found