Migrated tests in lib/analysis to JUnit 4.

--
MOS_MIGRATED_REVID=108862983
diff --git a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
index fc1b842..6e8275e 100644
--- a/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
+++ b/src/main/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionAction.java
@@ -16,7 +16,6 @@
 
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Joiner;
-import com.google.common.base.Joiner.MapJoiner;
 import com.google.common.base.Objects;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
index 4b21b2e..db27f87 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectTest.java
@@ -22,9 +22,10 @@
 import static com.google.devtools.build.lib.packages.Attribute.attr;
 import static com.google.devtools.build.lib.packages.BuildType.LABEL;
 import static com.google.devtools.build.lib.packages.BuildType.LABEL_LIST;
+import static org.junit.Assert.fail;
 
 import com.google.devtools.build.lib.actions.util.ActionsTestUtil.NullAction;
-import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
+import com.google.devtools.build.lib.analysis.util.AnalysisTestCaseForJunit4;
 import com.google.devtools.build.lib.analysis.util.TestAspects;
 import com.google.devtools.build.lib.analysis.util.TestAspects.AspectInfo;
 import com.google.devtools.build.lib.analysis.util.TestAspects.AspectRequiringRule;
@@ -40,8 +41,6 @@
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -53,18 +52,7 @@
  * aspects can be tested even if they aren't used by regular rules.
  */
 @RunWith(JUnit4.class)
-public class AspectTest extends AnalysisTestCase {
-  @Override
-  @Before
-  public void setUp() throws Exception {
-    super.setUp();
-  }
-
-  @Override
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
+public class AspectTest extends AnalysisTestCaseForJunit4 {
 
   private final void setRules(RuleDefinition... rules) throws Exception {
     ConfiguredRuleClassProvider.Builder builder =
@@ -343,11 +331,10 @@
 
   @RunWith(JUnit4.class)
   public static class AspectTestWithoutLoading extends AspectTest {
+
     @Override
-    @Before
-    public void setUp() throws Exception {
-      disableLoading();
-      super.setUp();
+    protected boolean isLoadingEnabled() {
+      return false;
     }
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/AspectValueTest.java b/src/test/java/com/google/devtools/build/lib/analysis/AspectValueTest.java
index 15407b4..bb20661 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/AspectValueTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/AspectValueTest.java
@@ -15,7 +15,7 @@
 
 import com.google.common.testing.EqualsTester;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
-import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
+import com.google.devtools.build.lib.analysis.util.AnalysisTestCaseForJunit4;
 import com.google.devtools.build.lib.analysis.util.TestAspects.AttributeAspect;
 import com.google.devtools.build.lib.analysis.util.TestAspects.ExtraAttributeAspect;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -23,8 +23,6 @@
 import com.google.devtools.build.lib.packages.NativeAspectClass;
 import com.google.devtools.build.lib.skyframe.AspectValue;
 
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -33,18 +31,7 @@
  * Tests for {@link com.google.devtools.build.lib.skyframe.AspectValue}.
  */
 @RunWith(JUnit4.class)
-public class AspectValueTest extends AnalysisTestCase {
-  @Override
-  @Before
-  public void setUp() throws Exception {
-    super.setUp();
-  }
-
-  @Override
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
+public class AspectValueTest extends AnalysisTestCaseForJunit4 {
 
   @Test
   public void equality() throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BlazeDirectoriesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BlazeDirectoriesTest.java
index bd2fddc..ecf0db4 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BlazeDirectoriesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BlazeDirectoriesTest.java
@@ -13,14 +13,23 @@
 // limitations under the License.
 package com.google.devtools.build.lib.analysis;
 
-import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import static org.junit.Assert.assertEquals;
+
+import com.google.devtools.build.lib.testutil.FoundationTestCaseForJunit4;
 import com.google.devtools.build.lib.vfs.FileSystem;
 import com.google.devtools.build.lib.vfs.Path;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Unit tests for {@link BlazeDirectories}.
  */
-public class BlazeDirectoriesTest extends FoundationTestCase {
+@RunWith(JUnit4.class)
+public class BlazeDirectoriesTest extends FoundationTestCaseForJunit4 {
+
+  @Test
   public void testCreatingDirectories() {
     FileSystem fs = scratch.getFileSystem();
     Path installBase = fs.getPath("/my/install");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
index abcdc3f..23d0354 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/BuildViewTest.java
@@ -61,6 +61,7 @@
 import com.google.devtools.build.skyframe.SkyKey;
 import com.google.devtools.build.skyframe.TrackingAwaiter;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.JUnit4;
@@ -156,6 +157,8 @@
 
   // TODO(bazel-team): this test is bad, it seems to rely on genrule emitting a warning to make the
   // analysis fail, this needs a proper way to inject errors/warnings
+  @Test
+  @Ignore
   public void disabled_testReportsAnalysisRootCauses() throws Exception {
     scratch.file("pkg/BUILD",
         "genrule(name='foo',",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/CompositeRunfilesSupplierTest.java b/src/test/java/com/google/devtools/build/lib/analysis/CompositeRunfilesSupplierTest.java
index 9845985..4f7627b 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/CompositeRunfilesSupplierTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/CompositeRunfilesSupplierTest.java
@@ -48,7 +48,7 @@
   private CompositeRunfilesSupplier underTest;
 
   @Before
-  public void setup() throws IOException {
+  public final void createMocks() throws IOException {
     Scratch scratch = new Scratch();
     rootDir = Root.asDerivedRoot(scratch.dir("/fake/root/dont/matter"));
 
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java
index e83160e..8642117 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/ConfiguredAttributeMapperTest.java
@@ -14,16 +14,21 @@
 package com.google.devtools.build.lib.analysis;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.analysis.config.CompilationMode;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.packages.Attribute;
 import com.google.devtools.build.lib.packages.AttributeMap;
 import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.syntax.Type;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -36,7 +41,8 @@
  * com.google.devtools.build.lib.analysis.select.AbstractAttributeMapperTest} to run tests common to
  * all attribute mappers.
  */
-public class ConfiguredAttributeMapperTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class ConfiguredAttributeMapperTest extends BuildViewTestCaseForJunit4 {
 
   /**
    * Returns a ConfiguredAttributeMapper bound to the given rule with the target configuration.
@@ -60,6 +66,7 @@
    * Tests that {@link ConfiguredAttributeMapper#get} only gets the configuration-appropriate
    * value.
    */
+  @Test
   public void testGetAttribute() throws Exception {
     writeConfigRules();
     scratch.file("a/BUILD",
@@ -86,6 +93,7 @@
   /**
    * Tests that label visitation only travels down configuration-appropriate paths.
    */
+  @Test
   public void testLabelVisitation() throws Exception {
     writeConfigRules();
     scratch.file("a/BUILD",
@@ -142,6 +150,7 @@
    * Tests that for configurable attributes where the *values* are evaluated in different
    * configurations, the configuration checking still uses the original configuration.
    */
+  @Test
   public void testConfigurationTransitions() throws Exception {
     writeConfigRules();
     scratch.file("a/BUILD",
@@ -177,6 +186,7 @@
     assertEquals(CompilationMode.OPT, getHostConfiguration().getCompilationMode());
   }
 
+  @Test
   public void testConcatenatedSelects() throws Exception {
     scratch.file("hello/BUILD",
         "config_setting(name = 'a', values = {'define': 'foo=a'})",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
index 3bf70e8..31e3437 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/DependencyResolverTest.java
@@ -14,6 +14,7 @@
 package com.google.devtools.build.lib.analysis;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ListMultimap;
@@ -22,7 +23,7 @@
 import com.google.devtools.build.lib.analysis.DependencyResolver.Dependency;
 import com.google.devtools.build.lib.analysis.config.BuildConfiguration;
 import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
-import com.google.devtools.build.lib.analysis.util.AnalysisTestCase;
+import com.google.devtools.build.lib.analysis.util.AnalysisTestCaseForJunit4;
 import com.google.devtools.build.lib.analysis.util.TestAspects;
 import com.google.devtools.build.lib.analysis.util.TestAspects.AspectRequiringRule;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -33,7 +34,6 @@
 import com.google.devtools.build.lib.packages.Target;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 
-import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -52,14 +52,11 @@
  * easier this way.
  */
 @RunWith(JUnit4.class)
-public class DependencyResolverTest extends AnalysisTestCase {
+public class DependencyResolverTest extends AnalysisTestCaseForJunit4 {
   private DependencyResolver dependencyResolver;
 
-  @Override
   @Before
-  public void setUp() throws Exception {
-    super.setUp();
-
+  public final void createResolver() throws Exception {
     dependencyResolver = new DependencyResolver() {
       @Override
       protected void invalidVisibilityReferenceHook(TargetAndConfiguration node, Label label) {
@@ -83,12 +80,6 @@
     };
   }
 
-  @Override
-  @After
-  public void tearDown() throws Exception {
-    super.tearDown();
-  }
-
   private void pkg(String name, String... contents) throws Exception {
     scratch.file("" + name + "/BUILD", contents);
   }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java b/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
index cc7d9a9..7209623 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/LabelExpanderTest.java
@@ -13,23 +13,31 @@
 // limitations under the License.
 package com.google.devtools.build.lib.analysis;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.cmdline.LabelSyntaxException;
 import com.google.devtools.build.lib.testutil.Suite;
 import com.google.devtools.build.lib.testutil.TestSpec;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.Map;
 
 /**
  * Tests for {@link LabelExpander}.
  */
 @TestSpec(size = Suite.SMALL_TESTS)
-public class LabelExpanderTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class LabelExpanderTest extends BuildViewTestCaseForJunit4 {
   /**
    * A dummy target that resolves labels and receives errors.
    */
@@ -115,6 +123,7 @@
   /**
    * Tests that if no mapping is specified, then strings expand to themselves.
    */
+  @Test
   public void testStringExpandsToItselfWhenNoMappingSpecified() throws Exception {
     setupDummy();
     assertExpansion("", null);
@@ -127,6 +136,7 @@
    * Tests that in case of a one-to-one label-to-artifact mapping the expansion
    * produces the expected results.
    */
+  @Test
   public void testExpansion() throws Exception {
     setupDummy();
     assertExpansion("foo/x1", "x1", ImmutableMap.<Label, Iterable<Artifact>>of(
@@ -143,6 +153,7 @@
    * Tests that label extraction works as expected - disallowed label characters
    * are resolved to themselves.
    */
+  @Test
   public void testLabelExtraction() throws Exception {
     setupDummy();
     assertExpansion("(foo/" + allowedChars + ")", "(//foo:" + allowedChars + ")",
@@ -159,6 +170,7 @@
   /**
    * Tests that an exception is thrown when the mapping is not one-to-one.
    */
+  @Test
   public void testThrowsWhenMappingIsNotOneToOne() throws Exception {
     setupDummy();
     try {
@@ -184,6 +196,7 @@
   /**
    * Tests expanding labels that result in a SyntaxException.
    */
+  @Test
   public void testIllFormedLabels() throws Exception {
     setupDummy();
     assertExpansion("x1:x2:x3", "x1:x2:x3",
@@ -237,6 +250,7 @@
    * possible label). This means that if a label is a substring of another
    * label, it should not be expanded but be treated as part of the longer one.
    */
+  @Test
   public void testLabelIsSubstringOfValidLabel() throws Exception {
     setupDummy();
     assertExpansion("x3=foo/bar/x3", "x3=bar/x3",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/MakeVariableExpanderTest.java b/src/test/java/com/google/devtools/build/lib/analysis/MakeVariableExpanderTest.java
index 6f7d164..d5eb541 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/MakeVariableExpanderTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/MakeVariableExpanderTest.java
@@ -37,7 +37,7 @@
   private Map<String, String> vars = new HashMap<>();
 
   @Before
-  public void setUp() throws Exception {
+  public final void createContext() throws Exception  {
     context = new MakeVariableExpander.Context() {
         @Override
         public String lookupMakeVariable(String name)
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesSupplierImplTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesSupplierImplTest.java
index 610f63a..8626f69 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesSupplierImplTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesSupplierImplTest.java
@@ -42,7 +42,7 @@
   private Root middlemanRoot;
 
   @Before
-  public void setup() throws IOException {
+  public final void setRoot() throws IOException {
     Scratch scratch = new Scratch();
     rootDir = Root.asDerivedRoot(scratch.dir("/fake/root/dont/matter"));
 
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
index 23e7e57..a38fbfc 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/RunfilesTest.java
@@ -14,22 +14,28 @@
 package com.google.devtools.build.lib.analysis;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
 
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.Root;
 import com.google.devtools.build.lib.events.EventKind;
-import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.FoundationTestCaseForJunit4;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.HashMap;
 import java.util.Map;
 
 /**
  * Test for {@link Runfiles}.
  */
-public class RunfilesTest extends FoundationTestCase {
+@RunWith(JUnit4.class)
+public class RunfilesTest extends FoundationTestCaseForJunit4 {
 
   private void checkWarning() {
     assertContainsEvent("obscured by a -> /workspace/a");
@@ -38,6 +44,7 @@
     assertEquals(EventKind.WARNING, Iterables.getOnlyElement(eventCollector).getKind());
   }
 
+  @Test
   public void testFilterListForObscuringSymlinksCatchesBadObscurer() throws Exception {
     Map<PathFragment, Artifact> obscuringMap = new HashMap<>();
     PathFragment pathA = new PathFragment("a");
@@ -51,6 +58,7 @@
     checkWarning();
   }
 
+  @Test
   public void testFilterListForObscuringSymlinksCatchesBadGrandParentObscurer() throws Exception {
     Map<PathFragment, Artifact> obscuringMap = new HashMap<>();
     PathFragment pathA = new PathFragment("a");
@@ -65,6 +73,7 @@
     checkWarning();
   }
 
+  @Test
   public void testFilterListForObscuringSymlinksCatchesBadObscurerNoListener() throws Exception {
     Map<PathFragment, Artifact> obscuringMap = new HashMap<>();
     PathFragment pathA = new PathFragment("a");
@@ -78,6 +87,7 @@
         .containsExactly(Maps.immutableEntry(pathA, artifactA)).inOrder();
   }
 
+  @Test
   public void testFilterListForObscuringSymlinksIgnoresOkObscurer() throws Exception {
     Map<PathFragment, Artifact> obscuringMap = new HashMap<>();
     PathFragment pathA = new PathFragment("a");
@@ -93,6 +103,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testFilterListForObscuringSymlinksNoObscurers() throws Exception {
     Map<PathFragment, Artifact> obscuringMap = new HashMap<>();
     PathFragment pathA = new PathFragment("a");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/BinaryFileWriteActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/BinaryFileWriteActionTest.java
index 744e92f..42ab272 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/BinaryFileWriteActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/BinaryFileWriteActionTest.java
@@ -18,8 +18,13 @@
 import com.google.devtools.build.lib.actions.ActionOwner;
 import com.google.devtools.build.lib.actions.Artifact;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.nio.charset.StandardCharsets;
 
+@RunWith(JUnit4.class)
 public class BinaryFileWriteActionTest extends FileWriteActionTestCase {
   @Override
   protected Action createAction(
@@ -28,22 +33,27 @@
         ByteSource.wrap(data.getBytes(StandardCharsets.UTF_8)), makeExecutable);
   }
 
+  @Test
   public void testNoInputs() {
     checkNoInputsByDefault();
   }
 
+  @Test
   public void testDestinationArtifactIsOutput() {
     checkDestinationArtifactIsOutput();
   }
 
+  @Test
   public void testCanWriteNonExecutableFile() throws Exception {
     checkCanWriteNonExecutableFile();
   }
 
+  @Test
   public void testCanWriteExecutableFile() throws Exception {
     checkCanWriteExecutableFile();
   }
 
+  @Test
   public void testComputesConsistentKeys() throws Exception {
     checkComputesConsistentKeys();
   }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java
index 50b3bc0..3b61e4f 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/CustomCommandLineTest.java
@@ -17,10 +17,17 @@
 
 import com.google.common.collect.ImmutableList;
 import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
-public class CustomCommandLineTest extends BuildViewTestCase {
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class CustomCommandLineTest extends BuildViewTestCaseForJunit4 {
+
+  @Test
   public void testAddBeforeEachPath() {
     CustomCommandLine commandLine = new CustomCommandLine.Builder()
         .add("foo")
@@ -35,6 +42,7 @@
         .inOrder();
   }
 
+  @Test
   public void testAddBeforeEach() {
     CustomCommandLine commandLine = new CustomCommandLine.Builder()
         .add("foo")
@@ -49,6 +57,7 @@
         .inOrder();
   }
 
+  @Test
   public void testAddBeforeEachExecPath() throws Exception {
     CustomCommandLine commandLine = new CustomCommandLine.Builder()
         .add("foo")
@@ -63,6 +72,7 @@
         .inOrder();
   }
 
+  @Test
   public void testAddFormatEach() {
     CustomCommandLine commandLine = new CustomCommandLine.Builder()
         .add("foo")
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java
index ea7ebf1..7d847c9 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTest.java
@@ -16,6 +16,11 @@
 import com.google.devtools.build.lib.actions.ActionOwner;
 import com.google.devtools.build.lib.actions.Artifact;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
 public class FileWriteActionTest extends FileWriteActionTestCase {
 
   @Override
@@ -24,22 +29,27 @@
     return new FileWriteAction(actionOwner, outputArtifact, data, makeExecutable);
   }
 
+  @Test
   public void testNoInputs() {
     checkNoInputsByDefault();
   }
 
+  @Test
   public void testDestinationArtifactIsOutput() {
     checkDestinationArtifactIsOutput();
   }
 
+  @Test
   public void testCanWriteNonExecutableFile() throws Exception {
     checkCanWriteNonExecutableFile();
   }
 
+  @Test
   public void testCanWriteExecutableFile() throws Exception {
     checkCanWriteExecutableFile();
   }
 
+  @Test
   public void testComputesConsistentKeys() throws Exception {
     checkComputesConsistentKeys();
   }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
index 6abbd9a..dda59a5 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/FileWriteActionTestCase.java
@@ -15,6 +15,10 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.actions.Action;
@@ -23,15 +27,17 @@
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.Executor;
 import com.google.devtools.build.lib.analysis.util.ActionTester;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
 import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 
+import org.junit.Before;
+
 import java.util.Collection;
 
-public abstract class FileWriteActionTestCase extends BuildViewTestCase {
+public abstract class FileWriteActionTestCase extends BuildViewTestCaseForJunit4 {
 
   private Action action;
   private Artifact outputArtifact;
@@ -39,13 +45,16 @@
   private Executor executor;
   private ActionExecutionContext context;
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createAction() throws Exception {
     outputArtifact = getBinArtifactWithNoOwner("destination.txt");
     output = outputArtifact.getPath();
     FileSystemUtils.createDirectoryAndParents(output.getParentDirectory());
     action = createAction(NULL_ACTION_OWNER, outputArtifact, "Hello World", false);
+  }
+
+  @Before
+  public final void createExecutorAndContext() throws Exception {
     executor = new TestExecutorBuilder(directories, binTools).build();
     context = new ActionExecutionContext(executor, null, null, new FileOutErr(), null);
   }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
index c2bc2f5..106416f 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/SpawnActionTest.java
@@ -16,6 +16,9 @@
 import static com.google.common.truth.Truth.assertThat;
 import static java.nio.charset.StandardCharsets.ISO_8859_1;
 import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
 
 import com.google.common.base.Strings;
 import com.google.common.collect.ImmutableList;
@@ -32,10 +35,15 @@
 import com.google.devtools.build.lib.analysis.util.ActionTester;
 import com.google.devtools.build.lib.analysis.util.ActionTester.ActionCombinationFactory;
 import com.google.devtools.build.lib.analysis.util.AnalysisTestUtil;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.testutil.MoreAsserts;
 import com.google.devtools.build.lib.vfs.PathFragment;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -45,7 +53,8 @@
 /**
  * Tests {@link SpawnAction}.
  */
-public class SpawnActionTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class SpawnActionTest extends BuildViewTestCaseForJunit4 {
   private Artifact welcomeArtifact;
   private Artifact destinationArtifact;
   private Artifact jarArtifact;
@@ -55,10 +64,8 @@
     return new SpawnAction.Builder();
   }
 
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
-
+  @Before
+  public final void createArtifacts() throws Exception {
     collectingAnalysisEnvironment = new AnalysisTestUtil.CollectingAnalysisEnvironment(
         getTestAnalysisEnvironment());
     welcomeArtifact = getSourceArtifact("pkg/welcome.txt");
@@ -84,18 +91,21 @@
     return (SpawnAction) actions[0];
   }
 
+  @Test
   public void testWelcomeArtifactIsInput() {
     SpawnAction copyFromWelcomeToDestination = createCopyFromWelcomeToDestination();
     Iterable<Artifact> inputs = copyFromWelcomeToDestination.getInputs();
     assertEquals(Sets.newHashSet(welcomeArtifact), Sets.newHashSet(inputs));
   }
 
+  @Test
   public void testDestinationArtifactIsOutput() {
     SpawnAction copyFromWelcomeToDestination = createCopyFromWelcomeToDestination();
     Collection<Artifact> outputs = copyFromWelcomeToDestination.getOutputs();
     assertEquals(Sets.newHashSet(destinationArtifact), Sets.newHashSet(outputs));
   }
 
+  @Test
   public void testBuilder() throws Exception {
     Artifact input = getSourceArtifact("input");
     Artifact output = getBinArtifactWithNoOwner("output");
@@ -116,6 +126,7 @@
     assertEquals("Test", action.getProgressMessage());
   }
 
+  @Test
   public void testBuilderWithExecutable() throws Exception {
     Action[] actions = builder()
         .setExecutable(welcomeArtifact)
@@ -127,6 +138,7 @@
         .containsExactlyElementsIn(asList(welcomeArtifact.getExecPath().getPathString()));
   }
 
+  @Test
   public void testBuilderWithJavaExecutable() throws Exception {
     Action[] actions = builder()
         .addOutput(destinationArtifact)
@@ -139,6 +151,7 @@
         "pkg/exe.jar", "MyMainClass"), action.getArguments());
   }
 
+  @Test
   public void testBuilderWithJavaExecutableAndParameterFile() throws Exception {
     useConfiguration("--min_param_file_size=0");
     collectingAnalysisEnvironment = new AnalysisTestUtil.CollectingAnalysisEnvironment(
@@ -170,6 +183,7 @@
         "pkg/exe.jar");
   }
 
+  @Test
   public void testBuilderWithJavaExecutableAndParameterFileAndParameterFileFlag() throws Exception {
     useConfiguration("--min_param_file_size=0");
     collectingAnalysisEnvironment = new AnalysisTestUtil.CollectingAnalysisEnvironment(
@@ -201,6 +215,7 @@
         "pkg/exe.jar");
   }
 
+  @Test
   public void testBuilderWithExtraExecutableArguments() throws Exception {
     Action[] actions = builder()
         .addOutput(destinationArtifact)
@@ -216,6 +231,7 @@
         action.getArguments());
   }
 
+  @Test
   public void testBuilderWithExtraExecutableArgumentsAndParameterFile() throws Exception {
     useConfiguration("--min_param_file_size=0");
     collectingAnalysisEnvironment = new AnalysisTestUtil.CollectingAnalysisEnvironment(
@@ -248,6 +264,7 @@
             ((ParameterFileWriteAction) getGeneratingAction(paramFile)).getContents()));
   }
 
+  @Test
   public void testParameterFiles() throws Exception {
     Artifact output1 = getBinArtifactWithNoOwner("output1");
     Artifact output2 = getBinArtifactWithNoOwner("output2");
@@ -276,6 +293,7 @@
     assertThat(spawnAction.getRemainingArguments()).containsExactly(longOption).inOrder();
   }
 
+  @Test
   public void testExtraActionInfo() throws Exception {
     SpawnAction copyFromWelcomeToDestination = createCopyFromWelcomeToDestination();
     ExtraActionInfo.Builder builder = copyFromWelcomeToDestination.getExtraActionInfo();
@@ -303,6 +321,7 @@
     }
   }
 
+  @Test
   public void testInputManifest() throws Exception {
     Artifact manifest = getSourceArtifact("MANIFEST");
     Action[] actions = builder()
@@ -318,6 +337,7 @@
     assertThat(inputFiles).isEmpty();
   }
 
+  @Test
   public void testComputeKey() throws Exception {
     final Artifact artifactA = getSourceArtifact("a");
     final Artifact artifactB = getSourceArtifact("b");
@@ -363,6 +383,7 @@
     });
   }
 
+  @Test
   public void testMnemonicMustNotContainSpaces() {
     SpawnAction.Builder builder = builder();
     try {
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
index 6781cdb..0aa2c63 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/SymlinkActionTest.java
@@ -15,21 +15,31 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.Sets;
 import com.google.devtools.build.lib.actions.ActionExecutionContext;
 import com.google.devtools.build.lib.actions.ActionExecutionException;
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.Executor;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Tests {@link SymlinkAction}.
  */
-public class SymlinkActionTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class SymlinkActionTest extends BuildViewTestCaseForJunit4 {
 
   private Path input;
   private Artifact inputArtifact;
@@ -37,9 +47,8 @@
   private Artifact outputArtifact;
   private SymlinkAction action;
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void setUp() throws Exception  {
     input = scratch.file("input.txt", "Hello, world.");
     inputArtifact = getSourceArtifact("input.txt");
     Path linkedInput = directories.getExecRoot().getRelative("input.txt");
@@ -52,16 +61,19 @@
         inputArtifact, outputArtifact, "Symlinking test");
   }
 
+  @Test
   public void testInputArtifactIsInput() {
     Iterable<Artifact> inputs = action.getInputs();
     assertEquals(Sets.newHashSet(inputArtifact), Sets.newHashSet(inputs));
   }
 
+  @Test
   public void testDestinationArtifactIsOutput() {
     Iterable<Artifact> outputs = action.getOutputs();
     assertEquals(Sets.newHashSet(outputArtifact), Sets.newHashSet(outputs));
   }
 
+  @Test
   public void testSymlink() throws Exception {
     Executor executor = new TestExecutorBuilder(directories, null).build();
     action.execute(new ActionExecutionContext(executor, null, null, null, null));
@@ -71,6 +83,7 @@
     assertEquals(outputArtifact, action.getPrimaryOutput());
   }
 
+  @Test
   public void testExecutableSymlink() throws Exception {
     Executor executor = new TestExecutorBuilder(directories, null).build();
     outputArtifact = getBinArtifactWithNoOwner("destination2.txt");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
index 60bc441..eaf2610 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/actions/TemplateExpansionActionTest.java
@@ -15,6 +15,8 @@
 
 import static com.google.common.truth.Truth.assertThat;
 import static com.google.devtools.build.lib.actions.util.ActionsTestUtil.NULL_ACTION_OWNER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -29,18 +31,24 @@
 import com.google.devtools.build.lib.analysis.actions.TemplateExpansionAction.Template;
 import com.google.devtools.build.lib.analysis.config.BinTools;
 import com.google.devtools.build.lib.exec.util.TestExecutorBuilder;
-import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.FoundationTestCaseForJunit4;
 import com.google.devtools.build.lib.util.io.FileOutErr;
 import com.google.devtools.build.lib.vfs.FileSystemUtils;
 import com.google.devtools.build.lib.vfs.Path;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.nio.charset.StandardCharsets;
 import java.util.List;
 
 /**
  * Tests {@link TemplateExpansionAction}.
  */
-public class TemplateExpansionActionTest extends FoundationTestCase {
+@RunWith(JUnit4.class)
+public class TemplateExpansionActionTest extends FoundationTestCaseForJunit4 {
 
   private static final String TEMPLATE = Joiner.on('\n').join("key=%key%", "value=%value%");
   private static final String SPECIAL_CHARS = "Š©±½_strøget";
@@ -53,9 +61,8 @@
   private BlazeDirectories directories;
   private BinTools binTools;
 
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createDirectoriesAndTools() throws Exception {
     createArtifacts(TEMPLATE);
 
     substitutions = Lists.newArrayList();
@@ -83,14 +90,17 @@
     return result;
   }
 
+  @Test
   public void testInputsIsEmpty() {
     assertThat(create().getInputs()).isEmpty();
   }
 
+  @Test
   public void testDestinationArtifactIsOutput() {
     assertEquals(ImmutableSet.of(outputArtifact), create().getOutputs());
   }
 
+  @Test
   public void testExpansion() throws Exception {
     Executor executor = new TestExecutorBuilder(directories, binTools).build();
     create().execute(createContext(executor));
@@ -99,6 +109,7 @@
     assertEquals(expected, content);
   }
 
+  @Test
   public void testKeySameIfSame() throws Exception {
     Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"),
         outputRoot);
@@ -111,6 +122,7 @@
     assertEquals(a.computeKey(), b.computeKey());
   }
 
+  @Test
   public void testKeyDiffersForSubstitution() throws Exception {
     Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"),
         outputRoot);
@@ -123,6 +135,7 @@
     assertFalse(a.computeKey().equals(b.computeKey()));
   }
 
+  @Test
   public void testKeyDiffersForExecutable() throws Exception {
     Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"),
         outputRoot);
@@ -135,6 +148,7 @@
     assertFalse(a.computeKey().equals(b.computeKey()));
   }
 
+  @Test
   public void testKeyDiffersForTemplates() throws Exception {
     Artifact outputArtifact2 = new Artifact(scratch.resolve("/workspace/out/destination.txt"),
         outputRoot);
@@ -173,20 +187,24 @@
     assertThat(actual).isEqualTo(expected);
   }
 
+  @Test
   public void testArtifactTemplateHasInput() {
     assertEquals(ImmutableList.of(inputArtifact), createWithArtifact().getInputs());
   }
 
+  @Test
   public void testArtifactTemplateHasOutput() {
     assertEquals(ImmutableSet.of(outputArtifact), createWithArtifact().getOutputs());
   }
 
+  @Test
   public void testArtifactTemplateExpansion() throws Exception {
     // The trailing "" is needed because scratch.overwriteFile implicitly appends "\n".
     String expected = Joiner.on('\n').join("key=foo", "value=bar", "");
     executeTemplateExpansion(expected);
   }
 
+  @Test
   public void testWithSpecialCharacters() throws Exception {
     // We have to overwrite the artifacts since we need our template in "inputs"
     createArtifacts(SPECIAL_CHARS + "%key%");
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/ConfigSettingTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/ConfigSettingTest.java
index c3ec6f3..0c80a1d 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/config/ConfigSettingTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/config/ConfigSettingTest.java
@@ -14,11 +14,16 @@
 package com.google.devtools.build.lib.analysis.config;
 
 import static com.google.common.truth.Truth.assertThat;
-import static com.google.devtools.build.lib.analysis.config.ConfigRuleClasses.ConfigSettingRule;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 import com.google.common.collect.ImmutableMap;
 import com.google.devtools.build.lib.Constants;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.config.ConfigRuleClasses.ConfigSettingRule;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.cmdline.Label;
 import com.google.devtools.build.lib.packages.Rule;
 import com.google.devtools.build.lib.rules.cpp.CppConfiguration;
@@ -27,12 +32,17 @@
 import com.google.devtools.common.options.OptionsBase;
 import com.google.devtools.common.options.OptionsParser;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.Map;
 
 /**
  * Tests for {@link ConfigSetting}.
  */
-public class ConfigSettingTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class ConfigSettingTest extends BuildViewTestCaseForJunit4 {
 
   private void writeSimpleExample() throws Exception {
     scratch.file("pkg/BUILD",
@@ -63,6 +73,7 @@
    * Tests that a config_setting only matches build configurations where *all* of
    * its flag specifications match.
    */
+  @Test
   public void testMatchingCriteria() throws Exception {
     writeSimpleExample();
 
@@ -86,6 +97,7 @@
   /**
    * Tests that {@link ConfigMatchingProvider#label} is correct.
    */
+  @Test
   public void testLabel() throws Exception {
     writeSimpleExample();
     assertEquals(
@@ -96,6 +108,7 @@
   /**
    * Tests that rule analysis fails on unknown options.
    */
+  @Test
   public void testUnknownOption() throws Exception {
     checkError("foo", "badoption",
         "unknown option: 'not_an_option'",
@@ -107,6 +120,7 @@
   /**
    * Tests that rule analysis fails on invalid option values.
    */
+  @Test
   public void testInvalidOptionValue() throws Exception {
     checkError("foo", "badvalue",
         "Not a valid compilation mode: 'baz'",
@@ -119,6 +133,7 @@
    * Tests that when the first option is valid but the config_setting doesn't match,
    * remaining options are still validity-checked.
    */
+  @Test
   public void testInvalidOptionFartherDown() throws Exception {
     checkError("foo", "badoption",
         "unknown option: 'not_an_option'",
@@ -133,6 +148,7 @@
   /**
    * Tests that *some* settings must be specified.
    */
+  @Test
   public void testEmptySettings() throws Exception {
     checkError("foo", "empty",
         "//foo:empty: no settings specified",
@@ -146,6 +162,7 @@
    * that take alternative defaults from what's specified in {@link
    * com.google.devtools.common.options.Option#defaultValue}).
    */
+  @Test
   public void testLateBoundOptionDefaults() throws Exception {
     String crosstoolCpuDefault = (String) getTargetConfiguration().getOptionValue("cpu");
     String crosstoolCompilerDefault = (String) getTargetConfiguration().getOptionValue("compiler");
@@ -168,6 +185,7 @@
   /**
    * Tests matching on multi-value attributes with key=value entries (e.g. --define).
    */
+  @Test
   public void testMultiValueDict() throws Exception {
     scratch.file("test/BUILD",
         "config_setting(",
@@ -193,6 +211,7 @@
   /**
    * Tests matching on multi-value attributes with primitive values.
    */
+  @Test
   public void testMultiValueList() throws Exception {
     scratch.file("test/BUILD",
         "config_setting(",
@@ -213,6 +232,7 @@
     assertTrue(getConfigMatchingProvider("//test:match").matches());
   }
 
+  @Test
   public void testSelectForDefaultCrosstoolTop() throws Exception {
     String crosstoolTop = Constants.TOOLS_REPOSITORY + "//tools/cpp:toolchain";
     scratchConfiguredTarget("a", "a",
@@ -220,6 +240,7 @@
         "sh_library(name='a', srcs=['a.sh'], deps=select({':cs': []}))");
   }
 
+  @Test
   public void testRequiredConfigFragmentMatcher() throws Exception {
     scratch.file("test/BUILD",
         "config_setting(",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java b/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java
index e7b32dc..1b60b03 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/config/StampTest.java
@@ -13,7 +13,9 @@
 // limitations under the License.
 package com.google.devtools.build.lib.analysis.config;
 
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import static org.junit.Assert.assertEquals;
+
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.packages.BuildType;
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.RuleFactory;
@@ -21,13 +23,19 @@
 import com.google.devtools.build.lib.packages.TriState;
 import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Tests for link stamping.
  */
-public class StampTest extends BuildViewTestCase {
+@RunWith(JUnit4.class)
+public class StampTest extends BuildViewTestCaseForJunit4 {
   /**
    * Tests that link stamping is disabled for all tests that support it.
    */
+  @Test
   public void testNoStampingForTests() throws Exception {
     RuleFactory ruleFactory = new RuleFactory(TestRuleClassProvider.getRuleClassProvider());
     for (String name : ruleFactory.getRuleClassNames()) {
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/constraints/AbstractConstraintsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/constraints/AbstractConstraintsTest.java
index 9b44af9..7268c22 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/constraints/AbstractConstraintsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/constraints/AbstractConstraintsTest.java
@@ -17,7 +17,7 @@
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Multimap;
-import com.google.devtools.build.lib.analysis.util.BuildViewTestCase;
+import com.google.devtools.build.lib.analysis.util.BuildViewTestCaseForJunit4;
 import com.google.devtools.build.lib.cmdline.Label;
 
 import java.util.Collection;
@@ -27,7 +27,7 @@
 /**
  * Common functionality for tests for the constraint enforcement system.
  */
-public abstract class AbstractConstraintsTest extends BuildViewTestCase {
+public abstract class AbstractConstraintsTest extends BuildViewTestCaseForJunit4 {
   /**
    * Creates an environment group on the scratch filesystem consisting of the specified
    * environments and specified defaults, set via a builder-style interface. The package name
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java
index 05d8189..29c56ce 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/constraints/ConstraintsTest.java
@@ -14,6 +14,8 @@
 package com.google.devtools.build.lib.analysis.constraints;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 
 import com.google.devtools.build.lib.analysis.BaseRuleClasses;
 import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
@@ -30,16 +32,21 @@
 import com.google.devtools.build.lib.testutil.UnknownRuleConfiguredTarget;
 import com.google.devtools.build.lib.util.FileTypeSet;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.Set;
 
 /**
  * Tests for the constraint enforcement system.
  */
+@RunWith(JUnit4.class)
 public class ConstraintsTest extends AbstractConstraintsTest {
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createBuildFile() throws Exception {
     // Support files for RuleClassWithImplicitAndLateBoundDefaults:
     scratch.file("helpers/BUILD",
         "sh_library(name = 'implicit', srcs = ['implicit.sh'])",
@@ -197,6 +204,7 @@
    * By default, a rule *implicitly* supports all defaults, meaning the explicitly known
    * environment set is empty.
    */
+  @Test
   public void testDefaultSupportedEnvironments() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     String ruleDef = getDependencyRule();
@@ -206,6 +214,7 @@
   /**
    * "Constraining" a rule's environments explicitly sets them.
    */
+  @Test
   public void testConstrainedSupportedEnvironments() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -217,6 +226,7 @@
   /**
    * Specifying compatibility adds the specified environments to the defaults.
    */
+  @Test
   public void testCompatibleSupportedEnvironments() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -228,6 +238,7 @@
   /**
    * A rule can't support *no* environments.
    */
+  @Test
   public void testSupportedEnvironmentsConstrainedtoNothing() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     reporter.removeHandler(failFastHandler);
@@ -239,6 +250,7 @@
   /**
    * Restrict the environments within one group, declare compatibility for another.
    */
+  @Test
   public void testSupportedEnvironmentsInMultipleGroups() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     new EnvironmentGroupMaker("buildenv/bar").setEnvironments("c", "d").setDefaults("c").make();
@@ -252,6 +264,7 @@
   /**
    * The same label can't appear in both a constraint and a compatibility declaration.
    */
+  @Test
   public void testSameEnvironmentCompatibleAndRestricted() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     reporter.removeHandler(failFastHandler);
@@ -264,6 +277,7 @@
   /**
    * Two labels from the same group can't appear in different attributes.
    */
+  @Test
   public void testSameGroupCompatibleAndRestricted() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     reporter.removeHandler(failFastHandler);
@@ -277,6 +291,7 @@
   /**
    * Tests that rule class defaults change a rule's default set of environments.
    */
+  @Test
   public void testSupportedEnvironmentsRuleClassDefaults() throws Exception {
     writeRuleClassDefaultEnvironments();
     String ruleDef = "rule_class_default(name = 'a')";
@@ -288,6 +303,7 @@
   /**
    * Tests that explicit declarations override rule class defaults.
    */
+  @Test
   public void testExplicitAttributesOverrideRuleClassDefaults() throws Exception {
     writeRuleClassDefaultEnvironments();
     String ruleDef = "rule_class_default("
@@ -304,6 +320,7 @@
    * Tests that a rule's "known" supported environments includes those from groups referenced
    * in rule class defaults but not in explicit rule attributes.
    */
+  @Test
   public void testKnownEnvironmentsIncludesThoseFromRuleClassDefaults() throws Exception {
     writeRuleClassDefaultEnvironments();
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
@@ -321,6 +338,7 @@
    * Tests that environments from the same group can't appear in both restriction and
    * compatibility rule class defaults.
    */
+  @Test
   public void testSameEnvironmentRuleClassCompatibleAndRestricted() throws Exception {
     writeRuleClassDefaultEnvironments();
     reporter.removeHandler(failFastHandler);
@@ -333,6 +351,7 @@
   /**
    * Tests that a dependency is valid if both rules implicitly inherit all default environments.
    */
+  @Test
   public void testAllDefaults() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -345,6 +364,7 @@
   /**
    * Tests that a dependency is valid when both rules explicitly declare the same constraints.
    */
+  @Test
   public void testSameConstraintsDeclaredExplicitly() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -358,6 +378,7 @@
    * Tests that a dependency is valid when both the depender and dependency explicitly declare
    * their constraints and the depender supports a subset of the dependency's environments
    */
+  @Test
   public void testValidConstraintsDeclaredExplicitly() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -371,6 +392,7 @@
    * Tests that a dependency is invalid when both the depender and dependency explicitly declare
    * their constraints and the depender supports an environment the dependency doesn't.
    */
+  @Test
   public void testInvalidConstraintsDeclaredExplicitly() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -386,6 +408,7 @@
    * Tests that a dependency is valid when both rules add the same set of environments to their
    * defaults.
    */
+  @Test
   public void testSameCompatibilityConstraints() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -400,6 +423,7 @@
    * Tests that a dependency is valid when both rules add environments to their defaults and
    * the depender only adds environments also added by the dependency.
    */
+  @Test
   public void testValidCompatibilityConstraints() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -414,6 +438,7 @@
    * Tests that a dependency is invalid when both rules add environments to their defaults and
    * the depender adds environments not added by the dependency.
    */
+  @Test
   public void testInvalidCompatibilityConstraints() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -429,6 +454,7 @@
   /**
    * Tests the error message when the dependency is missing multiple expected environments.
    */
+  @Test
   public void testMultipleMissingEnvironments() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -444,6 +470,7 @@
   /**
    * Tests a valid dependency including environments from different groups.
    */
+  @Test
   public void testValidMultigroupConstraints() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -460,6 +487,7 @@
   /**
    * Tests an invalid dependency including environments from different groups.
    */
+  @Test
   public void testInvalidMultigroupConstraints() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -479,6 +507,7 @@
    * Tests a valid dependency where the dependency doesn't "know" about the expected environment's
    * group, but implicitly supports it because that environment is a default.
    */
+  @Test
   public void testValidConstraintsUnknownEnvironmentToDependency() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a", "b")
         .make();
@@ -493,6 +522,7 @@
    * Tests an invalid dependency where the dependency doesn't "know" about the expected
    * environment's group and doesn't support it because it isn't a default.
    */
+  @Test
   public void testInvalidConstraintsUnknownEnvironmentToDependency() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a", "b")
         .make();
@@ -510,6 +540,7 @@
    * groups, the depender implicitly supports that group's defaults, and all of those defaults
    * are accounted for in the dependency.
    */
+  @Test
   public void testValidConstraintsUnknownEnvironmentToDependender() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -525,6 +556,7 @@
    * groups, the depender implicitly supports that group's defaults, and one of those defaults
    * isn't accounted for in the dependency.
    */
+  @Test
   public void testInvalidConstraintsUnknownEnvironmentToDependender() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
         .make();
@@ -540,6 +572,7 @@
   /**
    * Tests the case where one dependency is valid and another one isn't.
    */
+  @Test
   public void testOneDependencyIsInvalid() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -554,6 +587,7 @@
     assertDoesNotContainEvent("//hello:good_dep");
   }
 
+  @Test
   public void testConstraintEnforcementDisabled() throws Exception {
     useConfiguration("--experimental_enforce_constraints=0");
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b", "c").setDefaults("a")
@@ -569,6 +603,7 @@
    * Tests that package defaults compatibility produces a valid dependency that would otherwise
    * be invalid.
    */
+  @Test
   public void testCompatibilityPackageDefaults() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -582,6 +617,7 @@
   /**
    * Tests that a rule's compatibility declaration overrides its package defaults compatibility.
    */
+  @Test
   public void testPackageDefaultsCompatibilityOverride() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults().make();
     // We intentionally create an invalid dependency structure vs. a valid one. If we tested on
@@ -601,6 +637,7 @@
    * Tests that package defaults restriction produces an valid dependency that would otherwise
    * be invalid.
    */
+  @Test
   public void testRestrictionPackageDefaults() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a", "b")
         .make();
@@ -615,6 +652,7 @@
   /**
    * Tests that a rule's restriction declaration overrides its package defaults restriction.
    */
+  @Test
   public void testPackageDefaultsRestrictionOverride() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults().make();
     // We intentionally create an invalid dependency structure vs. a valid one. If we tested on
@@ -636,6 +674,7 @@
    * where the "compatible_with" / "restricted_to" values of rule class defaults are merged together
    * before being supplied to the rule. See comments in DependencyResolver for more discussion.
    */
+  @Test
   public void testPackageDefaultsDirectlyFillRuleAttributes() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults().make();
     scratch.file("hello/BUILD",
@@ -647,6 +686,7 @@
         + "environment group. They should be declared together either here or in restricted_to");
   }
 
+  @Test
   public void testHostDependenciesAreNotChecked() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -664,6 +704,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testHostDependenciesNotCheckedNoDistinctHostConfiguration() throws Exception {
     useConfiguration("--nodistinct_host_configuration");
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
@@ -682,6 +723,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testImplicitAndLateBoundDependenciesAreNotChecked() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -696,6 +738,7 @@
     assertDoesNotContainEvent("normal doesn't support expected environment");
   }
 
+  @Test
   public void testImplicitDepsWithWhiteListedAttributeAreChecked() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults("a").make();
     scratch.file("hello/BUILD",
@@ -708,6 +751,7 @@
         "dependency //helpers:implicit doesn't support expected environment: //buildenv/foo:b");
   }
 
+  @Test
   public void testOutputFilesAreChecked() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults().make();
     scratch.file("hello/BUILD",
@@ -723,6 +767,7 @@
         "dependency //hello:gen doesn't support expected environment: //buildenv/foo:a");
   }
 
+  @Test
   public void testConfigSettingRulesAreNotChecked() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo").setEnvironments("a", "b").setDefaults().make();
     scratch.file("hello/BUILD",
@@ -737,6 +782,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testFulfills() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
@@ -750,6 +796,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testFulfillsIsNotSymmetric() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
@@ -765,6 +812,7 @@
         "dependency //hello:dep doesn't support expected environment: //buildenv/foo:a");
   }
 
+  @Test
   public void testFulfillsIsTransitive() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b", "c")
@@ -779,6 +827,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testDefaultEnvironmentDirectlyFulfills() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
@@ -792,6 +841,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testDefaultEnvironmentIndirectlyFulfills() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b", "c")
@@ -806,6 +856,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testEnvironmentFulfillsExpectedDefault() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
@@ -819,6 +870,7 @@
     assertNoEvents();
   }
 
+  @Test
   public void testConstraintExemptRulesDontHaveConstraintAttributes() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
@@ -835,6 +887,7 @@
     assertContainsEvent("no such attribute 'restricted_to' in 'totally_free_rule'");
   }
 
+  @Test
   public void testBuildingEnvironmentGroupDirectlyDoesntCrash() throws Exception {
     new EnvironmentGroupMaker("buildenv/foo")
         .setEnvironments("a", "b")
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
index 5e6c31b..400729e 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AbstractAttributeMapperTest.java
@@ -14,6 +14,11 @@
 package com.google.devtools.build.lib.analysis.select;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
@@ -29,16 +34,22 @@
 import com.google.devtools.build.lib.packages.RuleClass;
 import com.google.devtools.build.lib.packages.util.PackageFactoryApparatus;
 import com.google.devtools.build.lib.syntax.Type;
-import com.google.devtools.build.lib.testutil.FoundationTestCase;
+import com.google.devtools.build.lib.testutil.FoundationTestCaseForJunit4;
 import com.google.devtools.build.lib.testutil.Scratch;
 import com.google.devtools.build.lib.vfs.Path;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.List;
 
 /**
  * Unit tests for {@link AbstractAttributeMapper}.
  */
-public class AbstractAttributeMapperTest extends FoundationTestCase {
+@RunWith(JUnit4.class)
+public class AbstractAttributeMapperTest extends FoundationTestCaseForJunit4 {
 
   private Package pkg;
   protected Rule rule;
@@ -61,9 +72,8 @@
     return pkg.getRule(ruleName);
   }
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void initializeRuleAndMapper() throws Exception {
     rule = createRule("x", "myrule",
         "cc_binary(name = 'myrule',",
         "          srcs = ['a', 'b', 'c'])");
@@ -71,17 +81,20 @@
     mapper = new TestMapper(pkg, ruleClass, rule.getLabel(), rule.getAttributeContainer());
   }
 
+  @Test
   public void testRuleProperties() throws Exception {
     assertEquals(rule.getName(), mapper.getName());
     assertEquals(rule.getLabel(), mapper.getLabel());
   }
 
+  @Test
   public void testPackageDefaultProperties() throws Exception {
     assertEquals(pkg.getDefaultHdrsCheck(), mapper.getPackageDefaultHdrsCheck());
     assertEquals(pkg.getDefaultTestOnly(), mapper.getPackageDefaultTestOnly());
     assertEquals(pkg.getDefaultDeprecation(), mapper.getPackageDefaultDeprecation());
   }
 
+  @Test
   public void testAttributeTypeChecking() throws Exception {
     // Good typing:
     mapper.get("srcs", BuildType.LABEL_LIST);
@@ -103,16 +116,19 @@
     }
   }
 
+  @Test
   public void testGetAttributeType() throws Exception {
     assertEquals(BuildType.LABEL_LIST, mapper.getAttributeType("srcs"));
     assertNull(mapper.getAttributeType("nonsense"));
   }
 
+  @Test
   public void testGetAttributeDefinition() {
     assertEquals("srcs", mapper.getAttributeDefinition("srcs").getName());
     assertNull(mapper.getAttributeDefinition("nonsense"));
   }
 
+  @Test
   public void testIsAttributeExplicitlySpecified() throws Exception {
     assertTrue(mapper.isAttributeValueExplicitlySpecified("srcs"));
     assertFalse(mapper.isAttributeValueExplicitlySpecified("deps"));
@@ -129,6 +145,7 @@
     }
   }
 
+  @Test
   public void testVisitation() throws Exception {
     VisitationRecorder recorder = new VisitationRecorder();
     mapper.visitLabels(recorder);
@@ -136,6 +153,7 @@
         .containsExactlyElementsIn(ImmutableList.of("//x:a", "//x:b", "//x:c"));
   }
 
+  @Test
   public void testComputedDefault() throws Exception {
     // Should return a valid ComputedDefault instance since this is a computed default:
     assertThat(mapper.getComputedDefault("$stl", BuildType.LABEL))
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
index 184a924..f4370c8 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/AggregatingAttributeMapperTest.java
@@ -14,6 +14,7 @@
 package com.google.devtools.build.lib.analysis.select;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertNull;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Iterables;
@@ -25,14 +26,19 @@
 import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.testutil.TestConstants;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Unit tests for {@link AggregatingAttributeMapper}.
  */
+@RunWith(JUnit4.class)
 public class AggregatingAttributeMapperTest extends AbstractAttributeMapperTest {
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createMapper() throws Exception {
     // Run AbstractAttributeMapper tests through an AggregatingAttributeMapper.
     mapper = AggregatingAttributeMapper.of(rule);
   }
@@ -41,6 +47,7 @@
    * Tests that {@link AggregatingAttributeMapper#visitAttribute} returns an
    * attribute's sole value when declared directly (i.e. not as a configurable dict).
    */
+  @Test
   public void testGetPossibleValuesDirectAttribute() throws Exception {
     Rule rule = createRule("a", "myrule",
         "sh_binary(name = 'myrule',",
@@ -53,6 +60,7 @@
    * Tests that {@link AggregatingAttributeMapper#visitAttribute} returns
    * every possible value that a configurable attribute can resolve to.
    */
+  @Test
   public void testGetPossibleValuesConfigurableAttribute() throws Exception {
     Rule rule = createRule("a", "myrule",
         "sh_binary(name = 'myrule',",
@@ -69,6 +77,7 @@
                 ImmutableList.of(Label.create("a", "default.sh"))));
   }
 
+  @Test
   public void testGetPossibleValuesWithConcatenatedSelects() throws Exception {
     Rule rule = createRule("a", "myrule",
         "sh_binary(name = 'myrule',",
@@ -92,6 +101,7 @@
    * Given a large number of selects, we expect better than the naive
    * exponential performance from evaluating select1 x select2 x select3 x ...
    */
+  @Test
   public void testGetPossibleValuesWithManySelects() throws Exception {
     String pattern = " + select({'//conditions:a1': '%c', '//conditions:a2': '%s'})";
     StringBuilder ruleDef = new StringBuilder();
@@ -110,6 +120,7 @@
    * Tests that, on rule visitation, {@link AggregatingAttributeMapper} visits *every* possible
    * value in a configurable attribute (including configuration key labels).
    */
+  @Test
   public void testVisitationConfigurableAttribute() throws Exception {
     Rule rule = createRule("a", "myrule",
         "sh_binary(name = 'myrule',",
@@ -127,6 +138,7 @@
                 "//a:a.sh", "//a:b.sh", "//a:default.sh", "//conditions:a", "//conditions:b"));
   }
 
+  @Test
   public void testGetReachableLabels() throws Exception {
     Rule rule = createRule("x", "main",
         "cc_binary(",
@@ -156,6 +168,7 @@
     assertThat(mapper.getReachableLabels("srcs", false)).containsExactlyElementsIn(valueLabels);
   }
 
+  @Test
   public void testDuplicateCheckOnNullValues() throws Exception {
     if (TestConstants.THIS_IS_BAZEL) {
       return;
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
index 37a1cbc..6023b6d 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/ConfiguredAttributeMapperCommonTest.java
@@ -18,6 +18,10 @@
 import com.google.devtools.build.lib.analysis.config.ConfigMatchingProvider;
 import com.google.devtools.build.lib.packages.AbstractAttributeMapper;
 
+import org.junit.Before;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Tests that {@link ConfiguredAttributeMapper} fulfills all behavior expected
  * of {@link AbstractAttributeMapper}.
@@ -27,10 +31,10 @@
  * inherit from {@link com.google.devtools.build.lib.analysis.util.BuildViewTestCase} to run tests
  * with build configurations.
  */
+@RunWith(JUnit4.class)
 public class ConfiguredAttributeMapperCommonTest extends AbstractAttributeMapperTest {
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createMapper() throws Exception {
     mapper = ConfiguredAttributeMapper.of(rule, ImmutableSet.<ConfigMatchingProvider>of());
   }
 }
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
index a7c035e..a634c11 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/NonconfigurableAttributeMapperTest.java
@@ -14,18 +14,25 @@
 package com.google.devtools.build.lib.analysis.select;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import com.google.devtools.build.lib.packages.NonconfigurableAttributeMapper;
 import com.google.devtools.build.lib.syntax.Type;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 /**
  * Unit tests for {@link NonconfigurableAttributeMapper}.
  */
+@RunWith(JUnit4.class)
 public class NonconfigurableAttributeMapperTest extends AbstractAttributeMapperTest {
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createRule() throws Exception {
     rule = createRule("x", "myrule",
         "cc_binary(",
         "    name = 'myrule',",
@@ -34,11 +41,13 @@
         "  deprecation = \"this rule is deprecated!\")");
   }
 
+  @Test
   public void testGetNonconfigurableAttribute() throws Exception {
     assertEquals("this rule is deprecated!",
         NonconfigurableAttributeMapper.of(rule).get("deprecation", Type.STRING));
   }
 
+  @Test
   public void testGetConfigurableAttribute() throws Exception {
     try {
       NonconfigurableAttributeMapper.of(rule).get("linkstatic", Type.BOOLEAN);
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
index fad95ff..0d9c761 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/select/RawAttributeMapperTest.java
@@ -14,6 +14,11 @@
 package com.google.devtools.build.lib.analysis.select;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableSet;
 import com.google.devtools.build.lib.cmdline.Label;
@@ -23,16 +28,21 @@
 import com.google.devtools.build.lib.packages.RawAttributeMapper;
 import com.google.devtools.build.lib.packages.Rule;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
 import java.util.List;
 
 /**
  * Unit tests for {@link RawAttributeMapper}.
  */
+@RunWith(JUnit4.class)
 public class RawAttributeMapperTest extends AbstractAttributeMapperTest {
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createMapper() throws Exception {
     // Run AbstractAttributeMapper tests through a RawAttributeMapper.
     mapper = RawAttributeMapper.of(rule);
   }
@@ -49,6 +59,7 @@
         "    data = [ ':data_a', ':data_b' ])");
   }
 
+  @Test
   public void testGetAttribute() throws Exception {
     RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
     List<Label> value = rawMapper.get("data", BuildType.LABEL_LIST);
@@ -67,12 +78,14 @@
   }
 
   @Override
+  @Test
   public void testGetAttributeType() throws Exception {
     RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
     assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("data")); // not configurable
     assertEquals(BuildType.LABEL_LIST, rawMapper.getAttributeType("srcs")); // configurable
   }
 
+  @Test
   public void testConfigurabilityCheck() throws Exception {
     RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
     assertFalse(rawMapper.isConfigurable("data", BuildType.LABEL_LIST));
@@ -82,6 +95,7 @@
   /**
    * Tests that RawAttributeMapper can't handle label visitation with configurable attributes.
    */
+  @Test
   public void testVisitLabels() throws Exception {
     RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
     try {
@@ -98,6 +112,7 @@
     }
   }
 
+  @Test
   public void testGetConfigurabilityKeys() throws Exception {
     RawAttributeMapper rawMapper = RawAttributeMapper.of(setupGenRule());
     assertThat(rawMapper.getConfigurabilityKeys("srcs", BuildType.LABEL_LIST))
@@ -109,6 +124,7 @@
     assertThat(rawMapper.getConfigurabilityKeys("data", BuildType.LABEL_LIST)).isEmpty();
   }
 
+  @Test
   public void testGetMergedValues() throws Exception {
     Rule rule = createRule("x", "myrule",
         "sh_binary(",
@@ -125,6 +141,7 @@
         .inOrder();
   }
 
+  @Test
   public void testMergedValuesWithConcatenatedSelects() throws Exception {
     Rule rule = createRule("x", "myrule",
         "sh_binary(",