Skip to content

Commit

Permalink
Bug: 1275 Support Junit 5.9 (#1276)
Browse files Browse the repository at this point in the history
* Bug: 1275 Support Junit 5.9

- added provider classes and configuration for new Junit 5.9

Signed-off-by: lnavrat <lumi@centrum.cz>
Change-Id: I3eff5b3f442a11a60f81b3b2e3386ec6343a7835

* Bug: 1275 Support Junit 5.9

- removed not needed modules

Signed-off-by: lnavrat <lumi@centrum.cz>
Change-Id: I19953e1a7550bdfd8e5bf01ec2311da04c926219

* Bug: 1275 Support Junit 5.9

- added integration test for provider (TODO set correct repo that contains junit 5.9.0)

Signed-off-by: lnavrat <lumi@centrum.cz>
Change-Id: I77d1f0f3aca079a9fbe02deeb09e3415af5ad952

* Bug: 1275 Support Junit 5.9

- added correct url for I repository
- fixed typo in test

Signed-off-by: lnavrat <lumi@centrum.cz>
Change-Id: Ia18f72abe899259d9168f6555dc420585bea51a9

Signed-off-by: lnavrat <lumi@centrum.cz>
  • Loading branch information
rimuln authored Aug 23, 2022
1 parent 1a0f2d5 commit 4f67446
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: JUnit59 Test Plug-in
Bundle-SymbolicName: bundle.test.junit59
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.junit.jupiter.api;version="5.9.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
35 changes: 35 additions & 0 deletions tycho-its/projects/surefire.junit59/bundle.test/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.tycho-its.surefire-junit5</groupId>
<artifactId>bundle.test.junit59</artifactId>
<packaging>eclipse-test-plugin</packaging>
<version>1.0.0</version>

<repositories>
<repository>
<id>eclipse202003</id>
<layout>p2</layout>
<url>${repo-2020-03}</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<excludedGroups>slow</excludedGroups>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2018 Bachmann electronic GmbH and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Bachmann electronic GmbH - initial API and implementation
*******************************************************************************/
package bundle.test;

import static org.junit.jupiter.api.Assertions.assertEquals;

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

class JUnit59Test {

@Test
@DisplayName("My 1st JUnit 5.9 test!")
void myFirstJUnit59Test(TestInfo testInfo) {
assertEquals(2, 1+1, "1 + 1 should equal 2");
assertEquals("My 1st JUnit 5.9 test!", testInfo.getDisplayName(), () -> "TestInfo is injected correctly");
}

@Test
@Tag("slow")
void slowJUnit5Test() {
assertEquals(2, 1+1, "1 + 1 should equal 2");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,15 @@ public void testJUnit56Runner() throws Exception {
assertNumberOfSuccessfulTests(projectBasedir, "bundle.test.JUnit56Test", 1);
}

@Test
public void testJUnit59Runner() throws Exception {
Verifier verifier = getVerifier("/surefire.junit59/bundle.test", false);
verifier.addCliOption("-Drepo-2020-03=" + "https:////download.eclipse.org/eclipse/updates/4.25-I-builds/");
verifier.executeGoal("verify");
verifier.verifyErrorFreeLog();
String projectBasedir = verifier.getBasedir();
assertTestMethodWasSuccessfullyExecuted(projectBasedir, "bundle.test.JUnit59Test", "My 1st JUnit 5.9 test!");
// make sure test tagged as 'slow' was skipped
assertNumberOfSuccessfulTests(projectBasedir, "bundle.test.JUnit59Test", 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Dependency> getRequiredBundles() {

@Override
protected VersionRange getJUnitVersionRange() {
return new VersionRange("[5.8,6.0)");
return new VersionRange("[5.8,5.9)");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public List<Dependency> getRequiredBundles() {

@Override
protected VersionRange getJUnitVersionRange() {
return new VersionRange("[5.8,6.0)");
return new VersionRange("[5.8,5.9)");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2018 SAP SE and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial API and implementation
*******************************************************************************/

package org.eclipse.tycho.surefire.provider.impl;

import static java.util.Collections.singletonList;
import static org.eclipse.tycho.surefire.provider.impl.ProviderHelper.newDependency;

import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.apache.maven.model.Dependency;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.tycho.classpath.ClasspathEntry;
import org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

@Component(role = TestFrameworkProvider.class, hint = "junit59")
public class JUnit59Provider extends AbstractJUnitProvider {

private static final Version VERSION = Version.parseVersion("5.9.0");

@Override
protected Set<String> getJUnitBundleNames() {
return Set.of("org.junit.jupiter.api" /* legacy Orbit bundle */, "junit-jupiter-api");
}

@Override
public String getSurefireProviderClassName() {
return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider";
}

@Override
public Version getVersion() {
return VERSION;
}

@Override
public List<Dependency> getRequiredBundles() {
return singletonList(newDependency("org.eclipse.tycho", "org.eclipse.tycho.surefire.junit58"));
}

@Override
protected VersionRange getJUnitVersionRange() {
return new VersionRange("[5.9,6.0)");
}

@Override
public boolean isEnabled(List<ClasspathEntry> testBundleClassPath, Properties surefireProperties) {
return super.isEnabled(testBundleClassPath, surefireProperties)
&& !new JUnit47Provider().containsJunitInClasspath(testBundleClassPath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*******************************************************************************
* Copyright (c) 2018 SAP SE and others.
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* SAP SE - initial API and implementation
*******************************************************************************/

package org.eclipse.tycho.surefire.provider.impl;

import static java.util.Collections.singletonList;
import static org.eclipse.tycho.surefire.provider.impl.ProviderHelper.newDependency;

import java.util.List;
import java.util.Properties;
import java.util.Set;

import org.apache.maven.model.Dependency;
import org.codehaus.plexus.component.annotations.Component;
import org.eclipse.tycho.classpath.ClasspathEntry;
import org.eclipse.tycho.surefire.provider.spi.TestFrameworkProvider;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

@Component(role = TestFrameworkProvider.class, hint = "junit59withvintage")
public class JUnit59WithVintageProvider extends AbstractJUnitProvider {

private static final Version VERSION = Version.parseVersion("5.9.0");

@Override
protected Set<String> getJUnitBundleNames() {
return Set.of("org.junit.jupiter.api" /* legacy Orbit bundle */, "junit-jupiter-api");
}

@Override
public String getSurefireProviderClassName() {
return "org.apache.maven.surefire.junitplatform.JUnitPlatformProvider";
}

@Override
public Version getVersion() {
return VERSION;
}

@Override
public List<Dependency> getRequiredBundles() {
return singletonList(newDependency("org.eclipse.tycho", "org.eclipse.tycho.surefire.junit58withvintage"));
}

@Override
protected VersionRange getJUnitVersionRange() {
return new VersionRange("[5.9,6.0)");
}

@Override
public boolean isEnabled(List<ClasspathEntry> testBundleClassPath, Properties surefireProperties) {
return super.isEnabled(testBundleClassPath, surefireProperties)
&& new JUnit47Provider().containsJunitInClasspath(testBundleClassPath);
}
}

0 comments on commit 4f67446

Please sign in to comment.