Skip to content

Commit

Permalink
fix: Run all sub-project tests in test_pack_doc.yml workflow (Mobil…
Browse files Browse the repository at this point in the history
…ityData#1382)

* Upgrade to Gradle 7.4 so that we can use the new `testReportAggregation`, which is a more standard way of aggregating test reports across all sub-projects.  Use this opportunity to consolidate a bunch of test options into the root project for consistent configuration.

* Comment tweak.

* Restore code to make sure `copyRulesMarkdown` runs before test execution.

* Make sure affected sources are in consistent sorted order for repeatable test execution.

* Disable UI tests in headless environments.

* Fix failing test on Windows due to line separators.

* Attempt MobilityData#2 to test correctly under Windows.

* Consolidate Java compile options for consistency across projects.  This will also help some tests pass on Windows environments.

* Get another test passing on Windows.
  • Loading branch information
bdferris-v2 authored and bradyhunsaker committed Apr 25, 2023
1 parent 503f8b6 commit 95f2f58
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 322 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/test_pack_doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,14 @@ jobs:
- name: Run tests on Java ${{ matrix.java_version }} and ${{ matrix.os }}
uses: gradle/gradle-build-action@v2
with:
arguments: testReport
- name: Persist **Passing** tests merged report - Java ${{ matrix.java_version }} on ${{ matrix.os }}
uses: actions/upload-artifact@v3
with:
name: Test report - Java ${{ matrix.java_version }} on ${{ matrix.os }}
path: build/reports/allTests/
- name: Persist **Failing** tests unmerged reports - Java ${{ matrix.java_version }} on ${{ matrix.os }}
# We run test aggregation with --continue to make sure all tests run, even if some fail.
arguments: testAggregateTestReport --continue
- name: Persist aggregated test reports on failure - Java ${{ matrix.java_version }} on ${{ matrix.os }}
if: ${{ failure() }}
uses: actions/upload-artifact@v3
with:
name: Test report - Java ${{ matrix.java_version }} on ${{ matrix.os }}
path: |
cli/build/reports/tests/
core/build/reports/tests/
main/build/reports/tests/
processor/build/reports/tests/
path: build/reports/tests/unit-test/aggregated-results/

package:
needs: [test]
Expand Down
6 changes: 0 additions & 6 deletions app/gui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ plugins {
id 'com.github.johnrengelman.shadow' version '5.2.0'
}

sourceCompatibility = JavaVersion.VERSION_11
mainClassName = 'org.mobilitydata.gtfsvalidator.app.gui.Main'
compileJava.options.encoding = "UTF-8"

repositories {
mavenCentral()
}

dependencies {
implementation project(':core')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import static com.google.common.truth.Truth8.assertThat;
import static org.mockito.Mockito.verify;

import java.awt.GraphicsEnvironment;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Path;
import javax.swing.JButton;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -33,6 +35,10 @@ public class GtfsValidatorAppTest {

@Before
public void before() {
// This test uses Swing and AWT classes that will fail if we are in a headless environment,
// so we skip the test if that's the case.
Assume.assumeFalse(GraphicsEnvironment.isHeadless());

this.app = new GtfsValidatorApp(runner, display);
app.constructUI();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import static com.google.common.truth.Truth.assertThat;

import java.awt.GraphicsEnvironment;
import java.nio.file.Path;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -20,12 +23,21 @@ public class GtfsValidatorPreferencesTest {
@Mock private MonitoredValidationRunner runner;
@Mock private ValidationDisplay display;

@Before
public void before() {
// This test uses Swing and AWT classes that will fail if we are in a headless environment,
// so we skip the test if that's the case.
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
}

@Test
public void testEndToEnd() {
Path outputDirectory = Path.of("/tmp/gtfs");

{
GtfsValidatorApp source = new GtfsValidatorApp(runner, display);
source.setGtfsSource("http://gtfs.org/gtfs.zip");
source.setOutputDirectory(Path.of("/tmp/gtfs"));
source.setOutputDirectory(outputDirectory);
source.setNumThreads(3);
source.setCountryCode("CA");

Expand All @@ -39,7 +51,7 @@ public void testEndToEnd() {
prefs.loadPreferences(dest);

assertThat(dest.getGtfsSource()).isEqualTo("http://gtfs.org/gtfs.zip");
assertThat(dest.getOutputDirectory()).isEqualTo("/tmp/gtfs");
assertThat(dest.getOutputDirectory()).isEqualTo(outputDirectory.toString());
assertThat(dest.getNumThreads()).isEqualTo(3);
assertThat(dest.getCountryCode()).isEqualTo("CA");
}
Expand Down
7 changes: 0 additions & 7 deletions app/pkg/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ plugins {
id "org.beryx.jlink" version "2.24.1"
}

repositories {
mavenCentral()
}

dependencies {
// Note that we depend on the :app:gui shadow jar, which bundles the gui
// application and all its dependencies into a single uber jar.
Expand Down Expand Up @@ -63,9 +59,6 @@ extraJavaModuleInfo {
}
}

sourceCompatibility = JavaVersion.VERSION_11
compileJava.options.encoding = "UTF-8"

java {
modularity.inferModulePath = true
}
Expand Down
64 changes: 39 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,54 +16,68 @@

plugins {
id 'java'
id 'test-report-aggregation'
id 'com.github.sherter.google-java-format' version '0.9'
id "io.freefair.aggregate-javadoc-jar" version "6.4.3"
id "pl.allegro.tech.build.axion-release" version "1.13.6"
}

repositories {
mavenCentral()
}

// Setup and configure Javadoc plugin
// Setup and configure properties that are consistent across all projects, including sub-modules.
allprojects {
group 'org.mobilitydata'

// Per the axion-release plugin, this computes the project version based
// on the most recent tag in the repo.
version scmVersion.version

repositories {
mavenCentral()
}

tasks.withType(JavaCompile) {
// All Java projects should target the same compatibility version.
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11

// Our source files should be encoded in UTF-8, regardless of the platform (e.g. Windows).
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
}

tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
}
}

// A resolvable configuration to collect test reports data
configurations {
testReportData {
canBeResolved = true
canBeConsumed = false
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'test-report-data'))
// All projects that include the 'java` plugin will have a Test task by default.
tasks.withType(Test) {
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'

// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}
}

dependencies {
testReportData project('main')
testReportData project(':processor')
testReportData project(':core')
// Define a system project for the project version
systemProperty 'gtfsValidatorVersionForTest', project.version

// Any project with a test should be added to test report aggregation in the root project.
rootProject.dependencies.add('testReportAggregation', project)
}
}

tasks.register('testReport', TestReport) {
destinationDir = file("$buildDir/reports/allTests")
// Use test results from testReportData configuration
testResultDirs.from(configurations.testReportData)
reporting {
reports {
// Necessary for unit test result aggregation.
testAggregateTestReport(AggregateTestReport) {
testType = TestSuiteType.UNIT_TEST
}
}
}

task copyRulesToWebClient (type: Copy) {
from "./RULES.md"
into "./web/client/static"
}

build.dependsOn copyRulesToWebClient
build.dependsOn copyRulesToWebClient
30 changes: 0 additions & 30 deletions cli/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,7 @@ shadowJar {
archiveClassifier = 'cli'
}

sourceCompatibility = JavaVersion.VERSION_11
mainClassName = 'org.mobilitydata.gtfsvalidator.cli.Main'
compileJava.options.encoding = "UTF-8"

repositories {
mavenCentral()
}

dependencies {
implementation project(':core')
Expand All @@ -68,27 +62,3 @@ dependencies {
testImplementation 'org.mockito:mockito-core:4.5.1'
}

test {
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'

// Show test results.
testLogging {
events "passed", "skipped", "failed"
}

systemProperty 'gtfsValidatorVersionForTest', project.version
}

// Share the test report data to be aggregated for the whole project
configurations {
binaryTestResultsElements {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'test-report-data'))
}
outgoing.artifact(test.binaryResultsDirectory)
}
}
30 changes: 0 additions & 30 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ plugins {
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_11
compileTestJava.options.encoding = "UTF-8"

repositories {
mavenCentral()
}

dependencies {
implementation project(':model')
annotationProcessor project(':processor:notices')
Expand Down Expand Up @@ -67,33 +60,10 @@ publishing {
}
}

test {
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'

// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}

compileJava {
options.compilerArgs << '-parameters'
}

compileTestJava {
options.compilerArgs << '-parameters'
}

// Share the test report data to be aggregated for the whole project
configurations {
binaryTestResultsElements {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, 'test-report-data'))
}
outgoing.artifact(test.binaryResultsDirectory)
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 95f2f58

Please sign in to comment.