Skip to content
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

jUnit 4 and @Rule execution order [SPR-7705] #12361

Closed
spring-projects-issues opened this issue Nov 1, 2010 · 4 comments
Closed

jUnit 4 and @Rule execution order [SPR-7705] #12361

spring-projects-issues opened this issue Nov 1, 2010 · 4 comments
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 1, 2010

Dries Schulten opened SPR-7705 and commented

When using Spring's SpringJUnit4ClassRunner to run unit-tests (the default runner for Spring's test base-classes) there is a execution order difference compared to default JUnit 4.

In the normal JUnit test runner (BlockJUnit4ClassRunner) it executes any @Rule's before running the @Before methods in a (base-)class. Spring's test runner first executes any @Before annotated methods before processing the @Rule's.

For example this causes a TestName JUnit rule (used to get the name of the currently executing test method) to be null in a @Before method.

The current SpringJUnit4ClassRunner fails on JUnit's own test suite because of this.

Attached is a patch with a fix (changes order of @Rule execution).


Affects: 3.0.5

Attachments:

Issue Links:

Referenced from: commits b109a07

0 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

Done. It didn't affect our test cases and I'm not sure many people are using @Rules yet (except perhaps you and me).

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

... And us! We are now affected by that bug too. Could you please consider merging that one back to 3.0.6?

@spring-projects-issues
Copy link
Collaborator Author

Dave Syer commented

Stephane, it's probably best to open a new ticket for 3.0.6. I would open a SpringSource support ticket as well if you have a deadline.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Jul 15, 2011

Stéphane Nicoll commented

Okay. Done (#13181)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

1 participant