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

Provide shorter 'alias' for SpringJUnit4ClassRunner [SPR-13954] #18527

Closed
spring-projects-issues opened this issue Feb 17, 2016 · 12 comments
Closed
Assignees
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Phil Webb opened SPR-13954 and commented

The SpringJUnit4ClassRunner is a bit of an ugly name and since it's now the only JUnit runner perhaps it could be renamed (or aliased) to something more succinct:

@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)

Referenced from: commits 9d3dd1b

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Note that we're following JUnit's own naming conventions there: The base class is called BlockJUnit4ClassRunner...

With JUnit 5 on the immediate horizon already, I'm not sure a renaming (i.e. the introduction of an empty subclass of SpringJUnit4ClassRunner with a shorter name) is worth it at this point.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

FWIW, JUnit actually introduced such a feature in JUnit 4.5: JUnit4 extends BlockJUnit4ClassRunner and is final.

So with JUnit you can annotate your test class like this: @RunWith(JUnit4.class).

I of course agree with Juergen that it's rather late in the game to do the same in Spring, but... even I would benefit from having to type less until Spring 5 / JUnit 5. ;)

And now for a wild and crazy idea...

How about introducing a final subclass of SpringJUnit4ClassRunner that is simply called Spring?

That would allow the following, super concise declaration:

@RunWith(Spring.class)

And... since we will never introduce any additional JUnit Runner (since JUnit 5 does not support runners), there's no reason to include any kind of version information in the class name.

Thoughts?

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Plus... I'm certain that a lot of developers will continue to use JUnit 4 even after JUnit 5 is released. And we naturally won't be dropping our JUnit 4 support in Spring 5. So with those points in mind, a shorter name/alias for the Spring runner would still be useful for years to come.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

OK, point taken, if even JUnit itself has a shortcut for it, it makes sense to have one of our own as well. That said, sorry, I can't swallow a class named "Spring" :-) Seriously, what if somebody else wants similar aliasing in e.g. a template language and also names their class "Spring" there. Auto-import trouble all over the place, aside from the strange looking class name. I also don't want this to show up like that when somebody says "Open Type" in the IDE, starting with "Spring".

On a related note, point taken that the version number doesn't have to be in there... but even JUnit has it in its JUnit4 runner name. To align with that, the best choice on our end seems to be SpringJUnit4? There's nothing wrong with making it immediately clear that it is about JUnit 4, given that JUnit 5 is around already, and assuming most people won't immediately realize that runners do not exist there anymore. It also leaves the option to name some other class SpringJUnit5... even if not a runner, there might be something else that suggests such a shortcut name at some point.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Ok, ok... no classes named simply Spring.

As I said, it was a wild and crazy idea (which I assumed would get shot down quickly). ;)

The reason that the JUnit team decided on JUnit4 as the name of the aliased runner is simply that they assumed that runners would exist in JUnit 5, 6, etc. But we now know that is not the case.

JUnit 5 has extensions instead of runners. So, in my prototype for Spring 5's JUnit 5 support, I have called our integration simply SpringExtension (which is currently registered like this: @ExtendWith(SpringExtension.class).

Thus it's probably a good idea to strive for some consistency in our naming conventions for runners and extensions.

I see two possibilities:

Including JUnit Version Numbers
@RunWith(SpringJUnit4.class)
public class MySpringJUnit4Tests { /* ... */ }
@ExtendWith(SpringJUnit5.class)
public class MySpringJUnit5Tests { /* ... */ }
Excluding JUnit Version Numbers
@RunWith(SpringRunner.class)
public class MySpringJUnit4Tests { /* ... */ }
@ExtendWith(SpringExtension.class)
public class MySpringJUnit5Tests { /* ... */ }

Thoughts?

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

I quite like that SpringJUnit4 vs SpringJUnit5 pairing there! Since "run" as well as "extend" is contained in the annotation names in both cases, it reads rather nicely if our class names just indicate Spring and the corresponding JUnit generation...

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

OK, unless we get significant negative feedback, I'll go with the SpringJUnit4 / SpringJUnit5 pairing.

Phil Webb, is SpringJUnit4 short enough for you? ;)

@spring-projects-issues
Copy link
Collaborator Author

Phil Webb commented

It's short but still a bit ugly. Is there any reason to include the version of JUnit in the class name? Since the runner is in org.springframework.test.context.junit4 is that not enough? I'd prefer:

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)

@spring-projects-issues
Copy link
Collaborator Author

Stéphane Nicoll commented

If SpringJUnit4 and SpringJUnit5 do not denote the same component, I wouldn't call them the same way. I like Phil's proposal.

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

The more I think about it, the more I like SpringRunner and SpringExtension.

Plus, we already have several precedents for duplicated class names in different packages. For example, consider LocalSessionFactoryBean of which we have three variants... in the hibernate3, hibernate4, and hibernate5 subpackages.

For a JUnit 4 Runner, there will only ever be one, the current one. For a JUnit 5 Extension, there will hopefully only ever be one (with updates as necessary for JUnit upgrades), and if a need should arise for an additional extension that could be given a new name or a new subpackage.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

SpringRunner and SpringExtension are fine by me...

@spring-projects-issues
Copy link
Collaborator Author

Sam Brannen commented

Completed as described in GitHub commit 9d3dd1b:

Introduce SpringRunner 'alias' for SpringJUnit4ClassRunner

This commit introduces a SpringRunner extension of SpringJUnit4ClassRunner that is intended to be used as an alias for SpringJUnit4ClassRunner, primarily in order to simplify configuration of JUnit 4 based integration tests.

Developers can use this alias as follows:

@RunWith(SpringRunner.class)
public class MySpringIntegrationTests { /* ... */ }

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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants