Skip to content

Commit

Permalink
Clean up the Bazel JUnit test runner
Browse files Browse the repository at this point in the history
To remove a dependency on Dagger quickly, the auto-generated boilerplate code was checked-in[1]. Since we are no longer using any dependency injection, most of the indirection with modules, suppliers/providers, etc are of no value.

This change also removes the duplication in `JUnit4BazelMock` by moving the test overrides into `JUnit4RunnerModule` / `JUnit4RunnerTest$TestModule`

[1] 225f69f

PiperOrigin-RevId: 518291786
Change-Id: I1b4ea99a0d4b5f0265fb98d98618e6232e247698
  • Loading branch information
hvadehra authored and copybara-github committed Mar 21, 2023
1 parent b079fd3 commit d6ad383
Show file tree
Hide file tree
Showing 47 changed files with 244 additions and 2,487 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,14 @@ package(
],
)

filegroup(
name = "common_runner_java_files",
srcs = [
"BazelTestRunnerModule.java",
"JUnit4Bazel.java",
"ResultWriterFactory.java",
"StderrStreamFactory.java",
"StdoutStreamFactory.java",
],
)

java_library(
name = "test_runner",
srcs = [
"BazelTestRunner.java",
":common_runner_java_files",
],
deps = [
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/internal",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/junit4",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/model",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/sharding",
"//src/java_tools/junitrunner/java/com/google/testing/junit/runner/util",
"//third_party:error_prone_annotations",
"//third_party:guava",
"//third_party:junit4",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
package com.google.testing.junit.runner;

import com.google.testing.junit.runner.internal.StackTraces;
import com.google.testing.junit.runner.junit4.JUnit4Bazel;
import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.Config;
import com.google.testing.junit.runner.junit4.JUnit4InstanceModules.SuiteClass;
import com.google.testing.junit.runner.junit4.JUnit4Runner;
import java.io.PrintStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -88,7 +89,7 @@ public static void main(String[] args) {

printStackTracesIfJvmExitHangs(stderr);

DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
Date shutdownTime = new Date();
String formattedShutdownTime = format.format(shutdownTime);
System.err.printf("-- JVM shutdown starting at %s --%n%n", formattedShutdownTime);
Expand Down Expand Up @@ -140,11 +141,7 @@ private static int runTestsInSuite(String suiteClassName, String[] args) {

// TODO(kush): Use a new classloader for the following instantiation.
JUnit4Runner runner =
JUnit4Bazel.builder()
.suiteClass(new SuiteClass(suite))
.config(new Config(args))
.build()
.runner();
JUnit4Bazel.builder().suiteClass(suite).config(new Config(args)).build().runner();
return runner.run().wasSuccessful() ? 0 : 1;
}

Expand Down

This file was deleted.

Loading

0 comments on commit d6ad383

Please sign in to comment.