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

[SUREFIRE-2010] Parameterized Selection Does not Work #476

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

DaGeRe
Copy link
Contributor

@DaGeRe DaGeRe commented Feb 24, 2022

This pull request provides the example project for an integration test, that checks whether selectors are able to select parameterized tests, e.g. package.TestClazz#method[1], where 1 is the index of the test.

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Make sure there is a JIRA issue filed
    for the change (usually before you start working on it). Trivial changes like typos do not
    require a JIRA issue. Your pull request should address just this issue, without
    pulling in other changes.
  • Each commit in the pull request should have a meaningful subject line and body.
  • Format the pull request title like [SUREFIRE-XXX] - Fixes bug in ApproximateQuantiles,
    where you replace SUREFIRE-XXX with the appropriate JIRA issue. Best practice
    is to use the JIRA issue title in the pull request title and in the first line of the
    commit message.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Run mvn clean install to make sure basic checks pass. A more thorough check will
    be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its clean install).

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

@Tibor17
Copy link
Contributor

Tibor17 commented Feb 24, 2022

Hi @DaGeRe ,

The JIRA is not well suited to read code patches. We can discuss the code even if the CI would fail.

{
@Test
public void testJUnit4() {
OutputValidator validator = unpack("surefire-2010-parameterized-selection-does-not-work").executeTest();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OutputValidator validator = is useless.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this was only for starting. The plan is to run it once with all tests and than with a selector.

Now, I've added

TestFile surefireReportsFile = validator.getSurefireReportsFile( "de.dagere.peass.ExampleTestJUnit4.txt" );
surefireReportsFile.assertContainsText( "Tests run: 2" );

which unfortunately fails.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to this parent POM specifies <forkMode>never</forkMode> it is a problem for all ITs and the tests won't run in a fork mode. There are two alternatives how to solve this. Override the parameter to the default value <forkMode>once</forkMode> or use <version>${surefire.version}</version>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I've added the forkMode.

import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

@RunWith(Parameterized.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to adjust the code style in these files well.
Pls configure your IDE, here is instructions and code style XML for your IDEs:
https://maven.apache.org/developers/conventions/code.html#intellij-idea

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank, I've imported the style and hopefully reformatted it correctly.

@Tibor17
Copy link
Contributor

Tibor17 commented Feb 25, 2022

@DaGeRe
If we want to test our documentation, we should use the pattern which would filter only some executions of parameterized test. Example mvn test -Dtest=*ExampleTestJUnit4#testMethod[5:*] and the IT allows you to assert lines in the logs and XML reports too. https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html

@olamy olamy added the bug label Mar 1, 2022
@DaGeRe
Copy link
Contributor Author

DaGeRe commented Mar 8, 2022

Thanks for the hints. I adapted the code, but is there any part of the maven launcher which allows to pass something like -Dtest=MySelector, or do I have to call it myself? Just adding it as goal ends in

[ERROR] Unknown lifecycle phase "test -Dtest=ExampleTestJUnit4". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version
>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, g
enerate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-cle
an, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

I can debug this with -Dmaven.surefire.debug=true, but that does not help to create the process correctly.

@chalmagr
Copy link
Contributor

chalmagr commented Jun 6, 2022

Thanks for the hints. I adapted the code, but is there any part of the maven launcher which allows to pass something like -Dtest=MySelector, or do I have to call it myself? Just adding it as goal ends in

[ERROR] Unknown lifecycle phase "test -Dtest=ExampleTestJUnit4". You must specify a valid lifecycle phase or a goal in the format <plugin-prefix>:<goal> or <plugin-group-id>:<plugin-artifact-id>[:<plugin-version
>]:<goal>. Available lifecycle phases are: validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, g
enerate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-cle
an, clean, post-clean, pre-site, site, post-site, site-deploy. -> [Help 1]

I can debug this with -Dmaven.surefire.debug=true, but that does not help to create the process correctly.

Make sure to use org.apache.maven.surefire.its.fixture.SurefireLauncher#sysProp to add the option and not the execute method execute("test -Dtest=...")

@andpab
Copy link
Contributor

andpab commented Jan 1, 2023

The best way to pass something like -Dtest=MySelector to the SurefireLauncher is to use SurefireLauncher#setTestToRun like this:

unpack( "surefire-2010-parameterized-selection-does-not-work" )
    .setTestToRun( "MySelector" )
    .executeTest();

@AlexShmydov
Copy link

AlexShmydov commented Apr 25, 2024

Hi all! Any news about this problem?

Is still actual on maven 3.1.2 and Junit 5.10.1

@Mohammad-gif
Copy link

',~-iç⟩fila=_‘u’_[I,\,ú\_,]”„·ū·”„f–pragnant era)—(it1613/°n-/~nkyun*-08',,-‘,-‘control·,·,cut fish]‹/\›... SCE

@AlexShmydov
Copy link

AlexShmydov commented Apr 29, 2024

Guys, can somebody to help?
I am talking about junit-team/junit5#2743 and https://issues.apache.org/jira/browse/SUREFIRE-1724
How we can run single invocation of test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
7 participants