Skip to content

Commit

Permalink
Fix #643 - tycho-surefire-plugin:integration-test does not execute any
Browse files Browse the repository at this point in the history
test

- add integration tests back
- generate a fragment to the host for additional imports
- if given try to load the provider from the maven dependency classpath

Signed-off-by: Christoph Läubrich <laeubi@laeubi-soft.de>
  • Loading branch information
laeubi committed Feb 11, 2022
1 parent eabe957 commit e787acd
Show file tree
Hide file tree
Showing 12 changed files with 312 additions and 41 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ bin/
.settings/
*.iml
.idea/
.tycho-consumer-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public Map<String, String> getPlatformProperties() {
@Override
public void addDevEntries(String id, String entries) {
if (entries != null) {
devEntries.put(id, entries);
devEntries.merge(id, entries, (s1, s2) -> s1 + "," + s2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public interface TychoConstants {
static final String CTX_TEST_DEPENDENCY_ARTIFACTS = CTX_BASENAME + "/testDependencyArtifacts";
static final String CTX_ECLIPSE_PLUGIN_PROJECT = CTX_BASENAME + "/eclipsePluginProject";
static final String CTX_ECLIPSE_PLUGIN_TEST_CLASSPATH = CTX_BASENAME + "/eclipsePluginTestClasspath";
static final String CTX_ECLIPSE_PLUGIN_TEST_EXTRA_CLASSPATH = CTX_BASENAME + "/eclipsePluginTestClasspathExtra";

static final String CTX_MERGED_PROPERTIES = CTX_BASENAME + "/mergedProperties";
static final String CTX_TARGET_PLATFORM_CONFIGURATION = CTX_BASENAME + "/targetPlatformConfiguration";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2011 Sonatype Inc. and others.
* Copyright (c) 2008, 2022 Sonatype Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -37,6 +37,8 @@ public interface BundleProject extends TychoProject {

public List<ArtifactKey> getExtraTestRequirements(ReactorProject project);

public List<ClasspathEntry> getTestClasspath(ReactorProject adapt);
public List<ClasspathEntry> getTestClasspath(ReactorProject project);

public List<ClasspathEntry> getTestClasspath(ReactorProject project, boolean complete);

}
Original file line number Diff line number Diff line change
Expand Up @@ -663,16 +663,28 @@ private void applyBestOfCurrentOrConfiguredProfile(String configuredProfileName,

@Override
public List<ClasspathEntry> getTestClasspath(ReactorProject reactorProject) {
@SuppressWarnings("unchecked")
return getTestClasspath(reactorProject, true);
}

@Override
@SuppressWarnings("unchecked")
public List<ClasspathEntry> getTestClasspath(ReactorProject reactorProject, boolean complete) {
List<ClasspathEntry> classpath = (List<ClasspathEntry>) reactorProject
.getContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_TEST_CLASSPATH);
if (classpath == null) {
List<ClasspathEntry> testClasspath = new ArrayList<>(getClasspath(reactorProject));
testClasspath.addAll(computeExtraTestClasspath(reactorProject));
Collection<ClasspathEntry> extraTestClasspath = computeExtraTestClasspath(reactorProject);
reactorProject.setContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_TEST_EXTRA_CLASSPATH, extraTestClasspath);
testClasspath.addAll(extraTestClasspath);
reactorProject.setContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_TEST_CLASSPATH, testClasspath);
return testClasspath;
}
return classpath;
if (complete) {
return classpath;
} else {
return (List<ClasspathEntry>) reactorProject
.getContextValue(TychoConstants.CTX_ECLIPSE_PLUGIN_TEST_EXTRA_CLASSPATH);
}
}

public DependencyArtifacts getTestDependencyArtifacts(ReactorProject project) {
Expand Down
13 changes: 7 additions & 6 deletions tycho-its/projects/surefire.combinedtests/bundle.test/.classpath
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="test" path="src_test">
<attributes>
Expand All @@ -18,5 +12,12 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ source.. = src/,src2/
output.. = bin/
bin.includes = META-INF/,\
.
additional.bundles = org.junit
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,59 @@
package org.eclipse.tycho.test.surefire;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.File;
import java.util.Arrays;

import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.eclipse.tycho.test.AbstractTychoIntegrationTest;
import org.junit.Test;

public class TestsInBundleTest extends AbstractTychoIntegrationTest {

@Test
public void testCompile() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "test-compile"));
verifier.verifyErrorFreeLog();
assertTrue("compiled class file does not exist",
new File(verifier.getBasedir(), "target/classes/bundle/test/Counter.class").exists());
assertTrue("compiled test-class file does not exist",
new File(verifier.getBasedir(), "target/test-classes/bundle/test/AdderTest.class").exists());
}

@Test
public void testTest() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "test"));
verifier.verifyErrorFreeLog();
assertTrue("tests were not run",
new File(verifier.getBasedir(), "target/surefire-reports/bundle.test.AdderTest.txt").exists());
}
@Test
public void testCompile() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "test-compile"));
verifier.verifyErrorFreeLog();
assertTrue("compiled class file does not exist",
new File(verifier.getBasedir(), "target/classes/bundle/test/Counter.class").exists());
assertTrue("compiled test-class file does not exist",
new File(verifier.getBasedir(), "target/test-classes/bundle/test/AdderTest.class").exists());
}

@Test
public void testTest() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "test"));
verifier.verifyErrorFreeLog();
assertTrue("tests were not run",
new File(verifier.getBasedir(), "target/surefire-reports/bundle.test.AdderTest.txt").exists());
}

@Test
public void testIntegrationTest() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
verifier.executeGoals(Arrays.asList("clean", "integration-test"));
verifier.verifyErrorFreeLog();
assertTrue("summary report not found",
new File(verifier.getBasedir(), "target/failsafe-reports/failsafe-summary.xml").exists());
verifier.verifyTextInLog("Tests run: 2, Failures: 1, Errors: 0, Skipped: 0");
verifier.verifyTextInLog("OSGiRunningIT.willFail:30 This fail is intentional");
}

@Test
public void testVerify() throws Exception {
Verifier verifier = getVerifier("surefire.combinedtests/bundle.test");
try {
verifier.executeGoals(Arrays.asList("clean", "verify"));
fail("the build succeed but test-failures are expected!");
} catch (VerificationException e) {
// thats good indeed...
verifier.verifyTextInLog("There are test failures");
}
}

}
7 changes: 7 additions & 0 deletions tycho-surefire/tycho-surefire-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>5.1.2</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>org.eclipse.tycho</groupId>
<artifactId>org.eclipse.tycho.surefire.osgibooter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public abstract class AbstractTestMojo extends AbstractMojo {
private String product;

@Parameter(property = "session", readonly = true, required = true)
private MavenSession session;
protected MavenSession session;

/**
* Run tests using UI (true) or headless (false) test harness.
Expand Down Expand Up @@ -426,7 +426,7 @@ public abstract class AbstractTestMojo extends AbstractMojo {
private Integer skipAfterFailureCount;

@Component
private RepositorySystem repositorySystem;
protected RepositorySystem repositorySystem;

@Component
private ResolutionErrorHandler resolutionErrorHandler;
Expand All @@ -447,7 +447,7 @@ public abstract class AbstractTestMojo extends AbstractMojo {
private EquinoxLauncher launcher;

@Component(role = TychoProject.class, hint = "eclipse-plugin")
private OsgiBundleProject osgiBundle;
protected OsgiBundleProject osgiBundle;

/**
* Normally tycho will automatically determine the test framework provider based on the test
Expand Down Expand Up @@ -783,7 +783,7 @@ private EquinoxInstallation createEclipseInstallation() throws MojoExecutionExce
return null;
}
TestFrameworkProvider provider = providerHelper.selectProvider(
getProjectType().getClasspath(DefaultReactorProject.adapt(project)), getMergedProviderProperties(),
getProjectType().getTestClasspath(DefaultReactorProject.adapt(project)), getMergedProviderProperties(),
providerHint);
DependencyResolver platformResolver = dependencyResolverLocator.lookupDependencyResolver(project);
final List<ArtifactKey> extraDependencies = getExtraDependencies();
Expand Down Expand Up @@ -841,6 +841,14 @@ public List<ArtifactKey> getExtraRequirements() {
testRuntime.addBundle(artifact);
}

setupTestBundles(provider, testRuntime);

getReportsDirectory().mkdirs();
return installationFactory.createInstallation(testRuntime, work);
}

protected void setupTestBundles(TestFrameworkProvider provider, EquinoxInstallationDescription testRuntime)
throws MojoExecutionException {
Set<Artifact> testFrameworkBundles = providerHelper.filterTestFrameworkBundles(provider, pluginArtifacts);
for (Artifact artifact : testFrameworkBundles) {
DevBundleInfo devInfo = workspaceState.getBundleInfo(session, artifact.getGroupId(),
Expand All @@ -856,9 +864,6 @@ public List<ArtifactKey> getExtraRequirements() {
}

testRuntime.addDevEntries(getTestBundleSymbolicName(), getBuildOutputDirectories());

getReportsDirectory().mkdirs();
return installationFactory.createInstallation(testRuntime, work);
}

private List<ArtifactKey> getExtraDependencies() {
Expand All @@ -880,7 +885,7 @@ private String getTestBundleSymbolicName() {
return getProjectType().getArtifactKey(getReactorProject()).getId();
}

private ArtifactKey getBundleArtifactKey(File file) throws MojoExecutionException {
protected ArtifactKey getBundleArtifactKey(File file) throws MojoExecutionException {
ArtifactKey key = osgiBundle.readArtifactKey(file);
if (key == null) {
throw new MojoExecutionException("Not an OSGi bundle " + file.getAbsolutePath());
Expand Down Expand Up @@ -996,6 +1001,14 @@ protected ScanResult scanForTests() {
TestListResolver resolver = new TestListResolver(includeList, excludeList);
DirectoryScanner scanner = new DirectoryScanner(getTestClassesDirectory(), resolver);
DefaultScanResult scanResult = scanner.scan();
List<String> classes = scanResult.getClasses();
for (String clazz : classes) {
getLog().debug("Class " + clazz + " matches the current filter.");
}
if (classes.isEmpty()) {
getLog().debug("Nothing matches pattern = " + includeList + " excluding " + excludeList + " in "
+ getTestClassesDirectory());
}
return scanResult;
}

Expand Down
Loading

0 comments on commit e787acd

Please sign in to comment.