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.

Backwards Compatibility: TestMethods require zero parameters

See original GitHub issue

Description

Upon upgrading unit tests from legacy MSTest to MSTest v2, I ran into the following breaking change. TestMethods throw exceptions if there are parameters, rather than getting skipped.

Steps to reproduce

Repro code:

    [TestClass]
    public class UnitTests
    {
        [TestMethod]
        public void Works()
        {
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void Breaks(string name)
        {
            Assert.IsTrue(true);
        }

        [TestMethod]
        public void AlsoBreaks(bool flag = false)
        {
            Assert.IsTrue(true);
        }
    }

Expected behavior

Legacy MSTest would ignore these methods completely. No errors or exceptions and they wouldn’t get run. It would be somewhat useful if “AlsoBreaks” would get run using the default parameter values.

Actual behavior

Unit test framework throws a cryptic exception: “Parameter count mismatch”.

Environment

Version .18 of MSTest on VS2015

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pvlakshmcommented, Jun 8, 2018

How about this as the error message: Only data driven test methods can have parameters. Did you intend to use [DataRow] or [DynamicData]?

2reactions
jayaranigargcommented, Jun 7, 2018

@MikeChristensen :

        [TestMethod]
        public void Breaks(string name)
        {
            Assert.IsTrue(true);
        }

We believe the only scenario user would write such a test where test method takes parameters would be when he wants to pass some data to the test and want to run as a data-driven test. But since no data is provided by the user, the only possible explanation to that would be that the user actually forgot to specify the data due to some reason. So rather than skipping the discovery(behavior of MSTestv1) where User may think tests are running successfully, it would be better if we flash a error message informing him that he missed specifying parameters(behavior of MSTestV2). Keeping the current behavior of MSTestV2 as it is makes more sense to us. Please share your thoughts in this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TestMethods require zero parameters · Issue #199 · ...
Description Upon upgrading unit tests from legacy MSTest to MSTest v2, ... Backwards Compatibility: TestMethods require zero parameters #199.
Read more >
Backward compatible when using three optional ...
Personally, I'd vote for a new method name: public void Test2(string a, TestOptions options = null) . Test2() will wrap the old Test()....
Read more >
Backward compatibility and overloading
The C# overloading rules prefer a method that doesn't need the compiler to “fill in” any optional parameters, but it doesn't have any...
Read more >
Changing method signature while keeping backwards ...
I need to change the expected signature of the callback function to accept additional arguments. This would be fine if everyones' callback ...
Read more >
Ensuring backward compatibility in your applications
In software development, Backward compatibility is an important concept that is often overlooked. This leads to stressful software updates ...
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