Backwards Compatibility: TestMethods require zero parameters
See original GitHub issueDescription
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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
How about this as the error message:
Only data driven test methods can have parameters. Did you intend to use [DataRow] or [DynamicData]?
@MikeChristensen :
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?