-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecate ExpectedException attribute. #135
Comments
@jimontheriver I agree. ExpectedException would probably be tagged with an obsolete tag in a future release. So building a project with an ExpectedException would start throwing warnings. |
We would need to fix the intellitest wizard that outputs ExpectedException in-tandem with this change so as not to break that workflow. |
I was actually thinking it would be better to extend it so that you can be more specific with the exception. i.e. permit specifying the error message (and/or the paramName). The attribute can save a lot of boilerplate code in tests when you are testing multiple failure paths. I agree though that, as is, its not as accurate as it could be. For instance, consider this code:
As is, there is no guarantee that the exception is being thrown on the property I'm intending. If someone inadvertently swaps the checks around, or adds a new property, this test could still pass even though its not on the correct check. To do this without the attribute requires something like this:
But by extending the attribute, you could do this:
This lets developers be much more specific with their Exception Testing. Overloading the constructors will allow this enhanced behaviour without breaking existing tests. |
We make use of this attribute, so please keep it. That you can specify a specific exception type is meeting our requirements for avoiding false 'test pass' situations. |
@robdalsanto you can specify a specific exception type Assert.ThrowsException<T>(Action action)
Assert.ThrowsExceptionAsync<T>(Func<Task> action) |
I suggest we make the attribute obsolete and provide a code refactoring to automatically rewrite the code to use new/better APIs. |
@Evangelink do you already have the code analyser in this repository for the refactoring tool ? I was looking for it but could not found it ? |
@fforjan Sadly there are none but I really want to add them! I was expecting to be working on that early this year but priorities have changed |
We will deprecate the attribute as part of |
After a couple of internal discussions, we want to try to be more strictly following semantic versioning as we have some users with huge test suite and this kind of change would lead to many failures and some time to fix or ignore. Pushing back to v4 as it will allow breaking changes. |
@Evangelink you self-assigned this ticket in December. It still has the Help-Wanted label. I assume that label is no longer applicable and should be removed? |
Hi @Kissaki, I wanted to release v4 a long time ago but we decided to postpone its release so we can group more breaking changes to avoid doing many breaks increments. We have already provided the analyzer so we only need to drop the attribute in v4. |
Description
I can still write tests that use ExpectedExceptionAttribute.
Steps to reproduce
Write this test
[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void TestMyStuff()
{
// arrange
var instanceUnderTest = new YourFunkyClass();
DoSomethingThatThrowsArgumentException();
// act // assert
Assert.ThrowsException(()=>instanceUnderTest.DoStuff("badargument");}
}
Expected behavior
I understand backwards compatibility, but ExpectedException is WIDELY recognized to be a source of tests passing when they should be failing. Any test with ExpectedException is effectively useless unless there are absolutely no other calls in the test. You just don't know if it's failing for the reason you expect it to fail, or if it's even getting to the line you want it to fail on.
At a minimum, there needs to be a way to set the test runner to reject it so that if someone brings it in, it fails. By MSTest 3, the attribute should go away entirely.
Actual behavior
I can still use it.
Environment
plain Win10, VS2017.
AB#1934068
The text was updated successfully, but these errors were encountered: