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

Introduce junit-platform-suite-api module #681

Closed
1 task done
smoyer64 opened this issue Feb 23, 2017 · 15 comments
Closed
1 task done

Introduce junit-platform-suite-api module #681

smoyer64 opened this issue Feb 23, 2017 · 15 comments

Comments

@smoyer64
Copy link
Contributor

smoyer64 commented Feb 23, 2017

Overview

Move the following Java types to a new junit-platform-suite-api module. These types will be useful to many engine developers and, other than the references to @RunWith(JUnitPlatform.class) in the javadocs, should not be tied to the vintage Runner.

  • ExcludeClassNamePatterns.java
  • ExcludeEngines.java
  • ExcludePackages.java
  • ExcludeTags.java
  • IncludeClassNamePatterns.java
  • IncludeEngines.java
  • IncludePackages.java
  • IncludeTags.java
  • SelectClasses.java
  • SelectPackages.java
  • UseTechnicalNames.java

Feature request

I've extended the JupiterTestEngine to create the JupiterSuiteEngine which supports an arbitrary hierarchy of test containers between the engine and test classes. At each level of the suite hierarchy, @BeforeSuite and @AfterSuite are supported, so you can also nest the hierarchy of setUp and tearDown. An example suite looks something like this:

@Suite
@IncludeClassNamePatterns("**/*JmqITs")
public class RequiresJmqSuite {
	
	@BeforeSuite
	void setUpJmqConnection() { ... }
	
	@AfterSuite
	void tearDownJmqConnection() { ... }

}

The JupiterSuiteEngine is currently hard-coded to scan for classes that end with "Suite" but it's my intention to have the engine consider the class name patterns and selections passed into the engine (once I make sure there won't be collisions with the JupiterTestEngine. You can obviously have more than one suite discovered by the engine in which case they will be peers in the test hierarchy.

In any case, when importing junit-platform-runner into my project, I also get the actual JUnit 4 Runner classes which I don't need. Worse yet, this implicit dependencies to my project which I don't need. My current work-around is to exclude these classes from the dependency graph as follows:

<dependency>
	<groupId>org.junit.platform</groupId>
	<artifactId>junit-platform-runner</artifactId>
	<version>${version.junit.platform}</version>
	<exclusions>
		<exclusion>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
		</exclusion>
		...
	</exclusions>
</dependency>

This obviously isn't the cleanest way to manage dependencies and it's my belief that the types listed above will be useful to many engine developers. As an aside, providing maintained interfaces to the utils/*Utils classes in junit-platform-commons will also help this project tremendously

Deliverables

  • Move each of the types listed above from junit-platform-runner to junit-platform-suite-api.
@gaganis
Copy link
Contributor

gaganis commented Feb 26, 2017

@smoyer64 I have the impression that if we did #691, migrating to the java library plugin, it would solve the implicit dependencies problems that you are mentioning. I suspect the junit dependency of the junit-platform-runner project would be an implementation dependency.

Even if the dep problem would be solved by #691, introducing a new project might still be valuable as it could it could clearly denote what the API is for building engines.

@marcphilipp
Copy link
Member

I think it has to be an api dependency because JUnitPlatform's public API contains references to JUnit 4 classes.

@sbrannen
Copy link
Member

This is something I've been wanting to do ever since we introduced the suite support for JUnit 4 on the platform.

I recommend moving the annotations to a module named junit-platform-suite-api.

And I'm slating this for inclusion before 5.0 GA so that the change is less disruptive for consumers of the API.

@sbrannen
Copy link
Member

The proposed JupiterSuiteEngine should then be addressed in a separate issue.

@sbrannen
Copy link
Member

Actually, I'd like to move the annotations in M4: the earlier, the better.

@junit-team/junit-lambda any objections?

@sbrannen sbrannen modified the milestones: 5.0 M4, 5.0 M5 Mar 13, 2017
@sormuras
Copy link
Member

Actually, I'd like to move the annotations in M4: the earlier, the better.

Sure. Go ahead!

@sbrannen
Copy link
Member

There are, however, some issues with this approach...

Since the suite annotations are open for use by anyone (i.e., any TestEngine), how will a given test engine know that it's supposed to actually honor the suite annotations and generate a suite in the test plan?

With the Vintage engine, it's straightforward since @RunWith(JUnitPlatform.class) must be present. But... with the Jupiter engine, what would be the trigger that signals to the Jupiter engine that it must create a suite?

Should the JUnit Platform itself actually honor the suite annotations instead of test engines taking over that job? For example, those annotations actually have a one-to-one correlation to selectors and filters already supported by the launcher APIs. So, the launcher could perhaps automatically detect those annotations and modify the request dynamically, before passing the request to any registered test engines.

Has anyone put any thought into these types of issues?

@sbrannen
Copy link
Member

@smoyer64, I just noticed your proposed @Suite annotation -- which I assume would be part of the junit-jupiter-api module -- right?

@smoyer64
Copy link
Contributor Author

@sbrannen I've already got the JupiterSuiteEngine running and was going to migrate it to junit-pioneer. And since it only uses the junit-engine-api, it's also capable of wrapping an engine that's not junit-jupiter-engine, I was planning to add support to use @IncludeEngines and rename the suite class to indicate it's for more than just the Jupiter engine. This proposal wasn't to add the suite functionality into JUnit5 at all but rather to simply eliminate the dependency on JUnit (vintage) that my suite implementation ended up with.

If you're saying this feature will be added into JUnit 5 itself, it seems that I should probably stop now - or at least coordinate adding this feature into the JUnit 5 codebase instead?

If you look at #687 you'll also find that this function could be accomplished as an Extension instead of an engine. I think in the long run this solution is even better ... other extensions might want to create test containers too? Right now I've also got @BeforeSuite/@AfterSuite but I'm leaning towards reusing @BeforeAll/@AfterAll so that the "all" is context dependent.

@sbrannen
Copy link
Member

@smoyer64, I honestly have not put a great deal of thought into this topic (at least not on the implementation level).

IMHO, the JUnit Platform would ideally provide support for declarative suites (e.g., configured via annotations) regardless of which test engines are registered.

That's about all I can contribute at the moment in terms of a vision.

Sooooo, my goal would be to make that vision become reality. But... I have yet to determine the feasibility of such a vision.

@sbrannen sbrannen changed the title Create junit-platform-api project Introduce junit-platform-suite-api module Mar 15, 2017
@sbrannen sbrannen self-assigned this Mar 15, 2017
@sbrannen
Copy link
Member

in progress

@sbrannen
Copy link
Member

@smoyer64, would you mind opening a new issue to address the JupiterSuiteEngine and your additional ideas in that regard?

sbrannen added a commit that referenced this issue Mar 16, 2017
Prior to this commit, annotations such as @SelectPackages,
@ExcludeTags, etc. were part of the junit-platform-runner module. This
unnecessarily tied these annotations to JUnit 4 even though these
annotations can theoretically be used by any engine or tool wishing to
allow users to configure test suites declaratively.

This commit addresses this issue by moving all such 'suite' annotations
from the `org.junit.platform.runner` package to the
`org.junit.platform.suite.api` package in a new
`junit-platform-suite-api` module.

Issue: #681
@sbrannen
Copy link
Member

Addressed in 248943f.

@smoyer64
Copy link
Contributor Author

I'd be happy to open another issue to (help) specify the declarative suite behavior and I'm more than happy to see it end up in the JUnit 5 itself. Assuming the suite's execution could hook into JUnit 5 in a non-public way, I'll leave it neutral with respect to #687 but that may still have some benefits.

This also seems like it's going to supercede junit-pioneer/junit-pioneer#35.

@sbrannen
Copy link
Member

Thanks, @smoyer64.

Please let me know once you're created the new issue (in case I miss it).

magictractor pushed a commit to magictractor/zillions that referenced this issue Apr 5, 2019
Test suites are broken, changes coming in 5.5/5.6, see
junit-team/junit5#681.

Plan to have sibling projects for BigInt implementations, can then
perhaps avoid use of suites.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants