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

Support JUnit @DisplayName #198

Closed
DariaMarkaryan opened this issue Jul 21, 2021 · 8 comments
Closed

Support JUnit @DisplayName #198

DariaMarkaryan opened this issue Jul 21, 2021 · 8 comments
Milestone

Comments

@DariaMarkaryan
Copy link

Hi. I'm using JUnit for run tests and it turns out that the @DisplayName does not work with tycho-surefire. I don't really care if I can use this particular annotation, it is important for me to change the names of the suites and test cases. Is there any way to do this?

@mickaelistria
Copy link
Contributor

I think it's a bug, @DisplayName is supposed to work.
Please provide a minimal example licensed under EPLv2, which we could try to include into Tycho test suite.

@DariaMarkaryan
Copy link
Author

DariaMarkaryan commented Jul 21, 2021

I'm using tycho-surefire 2.3.0 and JUnit 5.7.2
Test class just for an example:

package <...>;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.DisplayName;

@DisplayName("Custom name")
public class MyTests {

    @Test
    @DisplayName("My test name")
    public void uglyTestName(){
        System.out.println("Do something");
    }
}

and .pom

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
         xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <groupId>...</groupId>
    <artifactId>auto-test.ui</artifactId>
    <packaging>pom</packaging>

    <parent>
        <groupId>...</groupId>
        <artifactId>auto-test</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <relativePath>../</relativePath>
    </parent>

    <modules>
        <module>swtbot-simple</module>
    </modules>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.7.0</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-surefire-plugin</artifactId>
                <version>2.4.0</version>
                <configuration>
                    <useUIHarness>true</useUIHarness>
                    <useUIThread>false</useUIThread>
                    <product>ui.app.standalone.product</product>
                    <application>ui.app.standalone.standalone</application>
                    <testRuntime>default</testRuntime>
                    <bundleStartLevel>
                        <bundle>
                            <id>org.eclipse.osgi</id>
                            <level>-1</level>
                            <autoStart>true</autoStart>
                        </bundle>
                        <bundle>
                            <id>org.apache.felix.scr</id>
                            <level>2</level>
                            <autoStart>true</autoStart>
                        </bundle>
                        <bundle>
                            <id>org.eclipse.core.runtime</id>
                            <level>4</level>
                            <autoStart>true</autoStart>
                        </bundle>
                        <bundle>
                            <id>org.eclipse.equinox.common</id>
                            <level>2</level>
                            <autoStart>true</autoStart>
                        </bundle>
                        <bundle>
                            <id>org.eclipse.equinox.event</id>
                            <level>2</level>
                            <autoStart>true</autoStart>
                        </bundle>
                    </bundleStartLevel>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>target-platform-configuration</artifactId>
                <version>4.0.0</version>
                <configuration>
                    <dependency-resolution>
                        <extraRequirements>
                            <requirement>
                                <type>eclipse-feature</type>
                                <id>org.eclipse.rcp</id>
                                <versionRange>0.0.0</versionRange>
                            </requirement>
                            <requirement>
                                <type>eclipse-feature</type>
                                <id>org.eclipse.pde</id>
                                <versionRange>0.0.0</versionRange>
                            </requirement>
                        </extraRequirements>
                    </dependency-resolution>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

It generates report like that:

<?xml version="1.0" encoding="UTF-8"?>

-<testsuite failures="0" skipped="0" errors="0" tests="1" time="5.18" name="org.tests.MyTests" xsi:noNamespaceSchemaLocation="https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<properties/>
<testcase time="5.153" name="uglyTestName" classname="org.test.tests.MyTests"/>
</testsuite>

@DariaMarkaryan
Copy link
Author

And one additional question: is this possible to include logs into passed test cases?

@ghost
Copy link

ghost commented Nov 9, 2021

The behaviour of the maven-surefire-plugin changed some time ago; as far as i remeber there is a difference between JUnit4 and JUnit5 when it comes to handling display-name;

The new version of the surefire-plugin requiers additional configuration (see https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html#Surefire_Extensions_and_Reports_Configuration_for_.40DisplayName ). So far i wasn't able to figure out how to set these options when using tycho-surefire?

@mickaelistria mickaelistria changed the title Can I change name of test suite in surefire report? Support JUnit @DisplayName Nov 18, 2021
@joeshannon
Copy link
Contributor

I wonder if this would be possible using the providerProperties on the Tycho mojo?

However I've just seen that support for this was added to maven-surefire in version 3.0.0-M4 but Tycho currently uses 2.22.2 so that would probably have to be upgraded first I think.

@joeshannon
Copy link
Contributor

Tycho 3.0.0-SNAPSHOT does now have a version of Surefire that supports this however passing the required configuration looks like it might be non-trivial.

The configuration for tycho-surefire (TestPluginMojo/AbstractTestMojo) is written into a PropertiesWrapper and stored in a file which is then passed into the new Surefire OSGi booter process via an argument. The properties are a Map<String, String> at this point.

In Maven Surefire the required SurefireStatelessReporter, SurefireConsoleOutputReporter and SurefireStatelessTestsetInfoReporter objects are typed parameters on the Mojo. In Tycho these objects are created in the booter process - OsgiSurefireBooter, currently hardcoded to default implementations.

We would need a way to recreate these objects in the booter but the Map<String, String> of properties does not seem sufficient to allow this unless the raw xml was passed in and then deserialized in the booter process.

One option could be to add a tycho-surefire parameter such as enableJUnit5Reporting that, if enabled, OsgiSurefireBooter can configure itself using the default settings for JUnit5 as documented by Surefire but this doesn't feel like an ideal solution as it does not allow full flexibility.

Does this make sense?
Any thoughts on how we might achieve this?

@laeubi
Copy link
Member

laeubi commented Jun 9, 2022

Does this make sense?
Any thoughts on how we might achieve this?

Your best option would be to fetch the code and try out some of your suggestions, if your happy with them open a PR so we can discuss it.

joeshannon added a commit to joeshannon/tycho that referenced this issue Jun 9, 2022
@joeshannon
Copy link
Contributor

Have created a draft PR based on my previous comment.

joeshannon added a commit to joeshannon/tycho that referenced this issue Jun 9, 2022
joeshannon added a commit to joeshannon/tycho that referenced this issue Jun 14, 2022
If the test provider is the JUnitPlatformProvider then set up the
surefire reporting for JUnit5.

Issue eclipse-tycho#198.
joeshannon added a commit to joeshannon/tycho that referenced this issue Jun 27, 2022
If the test provider is JUnitPlatformProvider then set up the Surefire
reporting for JUnit5 as suggested in the Surefire documentation.

In the maven-surefire-plugin this configuration is expressed in the
pom. This approach does not work for Tycho as we have a separate OSGi
process executing the tests.

Instead we use the provider name to determine the reporting. This
doesn't offer the same flexibility as maven-surefire-plugin but should
be sufficient for initial support.

Fixes eclipse-tycho#198
@laeubi laeubi closed this as completed in 5670720 Jun 27, 2022
@laeubi laeubi added this to the 3.0 milestone Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants