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.

Undeprecate ExpectedException rule

See original GitHub issue

After 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:22 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
miralexancommented, Apr 16, 2020

@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:

StatusRuntimeException thrown = assertThrows(StatusRuntimeException.class, () -> {
   GrpcDispatch.makeRequest(service::enableJob, JobReference.newBuilder().setName(UNKNOWN_JOB).build());
});

assertEquals(Status.INVALID_ARGUMENT, thrown.getStatus());
2reactions
hjohncommented, Feb 29, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

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