Undeprecate ExpectedException rule
See original GitHub issueAfter upgrading the Spring Framework to JUnit 4.13 beta 3, I noticed that org.junit.rules.ExpectedException
is now @Deprecated
, and this change generates a lot of warnings in a large code base like that.
Since 4.13 is the last intended release in the 4.x line, I do not think it makes sense to deprecate such a commonly used and supported feature.
If you keep the deprecation in place, I fear that it will only annoy thousands (millions?) of developers for no good reason.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:22 (13 by maintainers)
Top Results From Across the Web
Alternatives to the deprecated ExpectedException.none() in ...
The ExceptedException.none() method to initialize a variable type of ExceptedException says it has been deprecated what are the alternatives to ...
Read more >ExpectedException (JUnit API)
The ExpectedException rule allows you to verify that your code throws a specific exception. Usage. public class SimpleExpectedExceptionTest { @Rule public ...
Read more >JUnit 4.13 assertThrows deprecates @Test(expected) and ...
JUnit 4.13 assertThrows deprecates @Test(expected) and @ Rule ExpectedException (Kotlin). 565 views 2 years ago. Fred Overflow. Fred Overflow.
Read more >Re: [nunit-discuss] NUnit 2.6, TestCaseSource and exception ...
ExpectedException or TestCaseData is something we want to get away from. Some people would like to have ... When we deprecate something ......
Read more >How do you assert that a certain exception is thrown in JUnit ...
Pull request #1519 : Deprecate ExpectedException ... I'm a fan of using the ExpectedException rule but it always bothered me that it breaks...
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
@daicoden
I’m pretty sure
assertThrows
returns the throwable, so you could just capture it and make assertions like you would for any other object:I also don’t understand why this deprecation should have happened in JUnit 4. I’m migrating to JUnit 5 using the
junit-vintage-engine
to support both versions temporarily. But this pulls in JUnit 4.13 which for some reason decided that it was a good idea to deprecate things (that have been supported for years) in what is likely one of its last releases.There also seems to be no reason for the deprecation other than to point out an alternative – this could have been achieved by at least offering an alternative (make the constructor public, or offer another static method – message communicated).
The
ExpectedException
code as it is now will continue working (and will keep working even in later releases) as it simply uses basic features of JUnit offered in an (at the time) convenient way.