Migrated EvaluationTestCase (and all tests depending on it) to JUnit 4.

--
MOS_MIGRATED_REVID=109064201
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
index 55aa373..cd7a716 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkCommandLineTest.java
@@ -25,14 +25,13 @@
 import org.junit.runners.JUnit4;
 
 /**
- * Tests for {@link SkylarkCommandLine}.
+ * Tests for {@link com.google.devtools.build.lib.rules.SkylarkCommandLine}.
  */
 @RunWith(JUnit4.class)
 public class SkylarkCommandLineTest extends SkylarkTestCase {
 
   @Before
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void generateBuildFile() throws Exception {
     scratch.file(
         "foo/BUILD",
         "genrule(name = 'foo',",
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
index 9307868..cfacebf 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkFileHelperTest.java
@@ -15,6 +15,7 @@
 package com.google.devtools.build.lib.skylark;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
 
 import com.google.devtools.build.lib.actions.Artifact;
 import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
@@ -33,8 +34,7 @@
 public class SkylarkFileHelperTest extends SkylarkTestCase {
 
   @Before
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void createBuildFile() throws Exception  {
     scratch.file(
         "foo/BUILD",
         "genrule(name = 'foo',",
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
index 1759103..1dc7896 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleClassFunctionsTest.java
@@ -15,6 +15,10 @@
 package com.google.devtools.build.lib.skylark;
 
 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.assertSame;
+import static org.junit.Assert.assertTrue;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
@@ -51,8 +55,7 @@
 public class SkylarkRuleClassFunctionsTest extends SkylarkTestCase {
 
   @Before
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void createBuildFile() throws Exception  {
     scratch.file(
         "foo/BUILD",
         "genrule(name = 'foo',",
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
index fdf229f..b740160 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleContextTest.java
@@ -15,6 +15,11 @@
 package com.google.devtools.build.lib.skylark;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -46,10 +51,8 @@
 @RunWith(JUnit4.class)
 public class SkylarkRuleContextTest extends SkylarkTestCase {
 
-  @Override
   @Before
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void generateBuildFile() throws Exception {
     scratch.file(
         "foo/BUILD",
         "genrule(name = 'foo',",
@@ -108,7 +111,7 @@
   }
 
   @Test
-  public void testNativeRuleAttributeErrorWithMacro() throws Exception {
+  public void hasCorrectLocationForRuleAttributeError_NativeRuleWithMacro() throws Exception {
     setUpAttributeErrorTest();
     try {
       createRuleContext("//test:m_native");
@@ -128,7 +131,7 @@
   }
 
   @Test
-  public void testSkylarkRuleAttributeErrorWithMacro() throws Exception {
+  public void hasCorrectLocationForRuleAttributeError_SkylarkRuleWithMacro() throws Exception {
     setUpAttributeErrorTest();
     try {
       createRuleContext("//test:m_skylark");
@@ -145,7 +148,7 @@
   }
 
   @Test
-  public void testNativeRuleAttributeErrorWithoutMacro() throws Exception {
+  public void hasCorrectLocationForRuleAttributeError_NativeRule() throws Exception {
     setUpAttributeErrorTest();
     try {
       createRuleContext("//test:cclib");
@@ -163,7 +166,7 @@
   }
 
   @Test
-  public void testSkylarkRuleAttributeErrorWithoutMacro() throws Exception {
+  public void hasCorrectLocationForRuleAttributeError_SkylarkRule() throws Exception {
     setUpAttributeErrorTest();
     try {
       createRuleContext("//test:skyrule");
@@ -296,7 +299,8 @@
   }
 
   @Test
-  public void testGetPrerequisiteArtifacts() throws Exception {
+  public void shouldGetPrerequisiteArtifacts() throws Exception {
+
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result = evalRuleContextCode(ruleContext, "ruleContext.files.srcs");
     assertArtifactList(result, ImmutableList.of("a.txt", "b.img"));
@@ -313,7 +317,7 @@
   }
 
   @Test
-  public void testGetPrerequisites() throws Exception {
+  public void shouldGetPrerequisites() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
     Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcs");
     // Check for a known provider
@@ -324,7 +328,7 @@
   }
 
   @Test
-  public void testGetPrerequisite() throws Exception {
+  public void shouldGetPrerequisite() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:asr");
     Object result = evalRuleContextCode(ruleContext, "ruleContext.attr.srcjar");
     TransitiveInfoCollection tic = (TransitiveInfoCollection) result;
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
index 7e5a9ee..82a6acb 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/SkylarkRuleImplementationFunctionsTest.java
@@ -15,6 +15,10 @@
 package com.google.devtools.build.lib.skylark;
 
 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.assertTrue;
+import static org.junit.Assert.fail;
 
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
@@ -41,6 +45,11 @@
 import com.google.devtools.build.lib.syntax.SkylarkSignature.Param;
 import com.google.devtools.build.lib.testutil.MoreAsserts;
 
+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;
 import java.util.Map;
@@ -49,6 +58,7 @@
 /**
  * Tests for SkylarkRuleImplementationFunctions.
  */
+@RunWith(JUnit4.class)
 public class SkylarkRuleImplementationFunctionsTest extends SkylarkTestCase {
 
   @SkylarkSignature(
@@ -68,9 +78,8 @@
   @SkylarkSignature(name = "throw", documented = false)
   BuiltinFunction throwFunction;
 
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  @Before
+  public final void createBuildFile() throws Exception  {
     scratch.file(
         "foo/BUILD",
         "genrule(name = 'foo',",
@@ -141,6 +150,7 @@
     }
   }
 
+  @Test
   public void testSkylarkFunctionPosArgs() throws Exception {
     setupSkylarkFunction("a = mock('a', 'b', mandatory_key='c')");
     Map<?, ?> params = (Map<?, ?>) lookup("a");
@@ -150,6 +160,7 @@
     assertEquals("x", params.get("optional_key"));
   }
 
+  @Test
   public void testSkylarkFunctionKwArgs() throws Exception {
     setupSkylarkFunction("a = mock(optional='b', mandatory='a', mandatory_key='c')");
     Map<?, ?> params = (Map<?, ?>) lookup("a");
@@ -159,6 +170,7 @@
     assertEquals("x", params.get("optional_key"));
   }
 
+  @Test
   public void testSkylarkFunctionTooFewArguments() throws Exception {
     checkSkylarkFunctionError(
         "insufficient arguments received by mock("
@@ -167,6 +179,7 @@
         "mock()");
   }
 
+  @Test
   public void testSkylarkFunctionTooManyArguments() throws Exception {
     checkSkylarkFunctionError(
         "too many (3) positional arguments in call to "
@@ -174,6 +187,7 @@
         "mock('a', 'b', 'c')");
   }
 
+  @Test
   public void testSkylarkFunctionAmbiguousArguments() throws Exception {
     checkSkylarkFunctionError(
         "argument 'mandatory' passed both by position and by name "
@@ -182,11 +196,13 @@
   }
 
   @SuppressWarnings("unchecked")
+  @Test
   public void testListComprehensionsWithNestedSet() throws Exception {
     Object result = eval("[x + x for x in set([1, 2, 3])]");
     assertThat((Iterable<Object>) result).containsExactly(2, 4, 6).inOrder();
   }
 
+  @Test
   public void testNestedSetGetsConvertedToSkylarkNestedSet() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result =
@@ -198,6 +214,7 @@
     assertEquals(Artifact.class, nset.getContentType().getType());
   }
 
+  @Test
   public void testCreateSpawnActionCreatesSpawnAction() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     createTestSpawnAction(ruleContext);
@@ -207,6 +224,7 @@
     assertThat(action).isInstanceOf(SpawnAction.class);
   }
 
+  @Test
   public void testCreateSpawnActionArgumentsWithCommand() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     createTestSpawnAction(ruleContext);
@@ -222,6 +240,7 @@
     assertEquals(targetConfig.getDefaultShellEnvironment(), action.getEnvironment());
   }
 
+  @Test
   public void testCreateSpawnActionArgumentsWithExecutable() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     evalRuleContextCode(
@@ -240,6 +259,7 @@
     MoreAsserts.assertContainsSublist(action.getArguments(), "foo/t.exe", "--a", "--b");
   }
 
+  @Test
   public void testCreateSpawnActionArgumentsBadExecutable() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -251,6 +271,7 @@
         "  executable = 'xyz.exe')");
   }
 
+  @Test
   public void testCreateSpawnActionShellCommandList() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     evalRuleContextCode(
@@ -270,6 +291,7 @@
         .inOrder();
   }
 
+  @Test
   public void testCreateSpawnActionEnvAndExecInfo() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     evalRuleContextCode(
@@ -291,6 +313,7 @@
     assertEquals(ImmutableMap.of("a", "b"), action.getExecutionInfo());
   }
 
+  @Test
   public void testCreateSpawnActionUnknownParam() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     checkErrorContains(
@@ -299,6 +322,7 @@
         "ruleContext.action(outputs=[], bad_param = 'some text')");
   }
 
+  @Test
   public void testCreateSpawnActionNoExecutable() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     checkErrorContains(
@@ -320,6 +344,7 @@
         "  use_default_shell_env = True)");
   }
 
+  @Test
   public void testCreateSpawnActionBadGenericArg() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -330,6 +355,7 @@
         "  command = 'dummy_command')");
   }
 
+  @Test
   public void testCreateSpawnActionCommandsListTooShort() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -339,6 +365,7 @@
         "  command = ['dummy_command', '--arg'])");
   }
 
+  @Test
   public void testCreateFileAction() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     FileWriteAction action =
@@ -354,6 +381,7 @@
     assertFalse(action.makeExecutable());
   }
 
+  @Test
   public void testEmptyAction() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
 
@@ -373,6 +401,7 @@
         .isEqualTo(Runtime.NONE);
   }
 
+  @Test
   public void testEmptyActionWithExtraAction() throws Exception {
     scratch.file(
         "test/empty.bzl",
@@ -405,6 +434,7 @@
     getPseudoActionViaExtraAction("//test:my_empty_action", "//test:listener");
   }
 
+  @Test
   public void testExpandLocation() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
 
@@ -463,6 +493,7 @@
         Pattern.matches(expectedPattern, computedValue));
   }
 
+  @Test
   public void testResolveCommandMakeVariables() throws Exception {
     evalRuleContextCode(
         createRuleContext("//foo:resolve_me"),
@@ -477,6 +508,7 @@
     assertThat(argv.get(2)).isEqualTo("I got the World on a string");
   }
 
+  @Test
   public void testResolveCommandInputs() throws Exception {
     evalRuleContextCode(
         createRuleContext("//foo:resolve_me"),
@@ -489,6 +521,7 @@
     assertThat(manifests).hasSize(1);
   }
 
+  @Test
   public void testResolveCommandExpandLocations() throws Exception {
     evalRuleContextCode(
         createRuleContext("//foo:resolve_me"),
@@ -510,6 +543,7 @@
     assertMatches("argv[2]", "A.*/mytool .*/mytool.sh B.*file3.dat", argv.get(2));
   }
 
+  @Test
   public void testResolveCommandScript() throws Exception {
     evalRuleContextCode(
         createRuleContext("//foo:resolve_me"),
@@ -526,6 +560,7 @@
     assertMatches("argv[1]", "^.*/resolve_me[.]script[.]sh$", argv.get(1));
   }
 
+  @Test
   public void testBadParamTypeErrorMessage() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     checkErrorContains(
@@ -538,6 +573,7 @@
         "  executable = False)");
   }
 
+  @Test
   public void testCreateTemplateAction() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     TemplateExpansionAction action =
@@ -562,6 +598,7 @@
    * Once {@link
    * com.google.devtools.build.lib.syntax.ParserInputSource#create(com.google.devtools.build.lib.vfs.Path)} parses files using UTF-8, this test will fail.
    */
+  @Test
   public void testCreateTemplateActionWithWrongEncoding() throws Exception {
     String value = "Š©±½";
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
@@ -587,6 +624,7 @@
     return new String(input.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
   }
 
+  @Test
   public void testGetProviderNotTransitiveInfoCollection() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -595,6 +633,7 @@
         "provider('some string', 'FileProvider')");
   }
 
+  @Test
   public void testGetProviderNonExistingClassType() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -605,6 +644,7 @@
         "func()");
   }
 
+  @Test
   public void testGetProviderNotTransitiveInfoProviderClassType() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:foo"),
@@ -615,6 +655,7 @@
         "func()");
   }
 
+  @Test
   public void testRunfilesAddFromDependencies() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
     Object result =
@@ -623,6 +664,7 @@
         .contains("libjl.jar");
   }
 
+  @Test
   public void testRunfilesStatelessWorksAsOnlyPosArg() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
     Object result =
@@ -631,12 +673,14 @@
         .contains("libjl.jar");
   }
 
+  @Test
   public void testRunfilesBadListGenericType() throws Exception {
     checkErrorContains(
         "Illegal argument: expected type File for 'files' element but got type string instead",
         "ruleContext.runfiles(files = ['some string'])");
   }
 
+  @Test
   public void testRunfilesBadSetGenericType() throws Exception {
     checkErrorContains(
         "expected set of Files or NoneType for 'transitive_files' while calling runfiles "
@@ -644,6 +688,7 @@
         "ruleContext.runfiles(transitive_files=set([1, 2, 3]))");
   }
 
+  @Test
   public void testRunfilesArtifactsFromArtifact() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result =
@@ -654,6 +699,7 @@
     assertThat(ActionsTestUtil.baseArtifactNames(getRunfileArtifacts(result))).contains("t.exe");
   }
 
+  @Test
   public void testRunfilesArtifactsFromIterableArtifacts() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result =
@@ -666,6 +712,7 @@
         ImmutableList.of("a.txt", "b.img"));
   }
 
+  @Test
   public void testRunfilesArtifactsFromNestedSetArtifacts() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result =
@@ -678,6 +725,7 @@
         ImmutableList.of("a.txt", "b.img"));
   }
 
+  @Test
   public void testRunfilesArtifactsFromDefaultAndFiles() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:bar");
     Object result =
@@ -697,6 +745,7 @@
     return ((Runfiles) runfiles).getAllArtifacts();
   }
 
+  @Test
   public void testRunfilesBadKeywordArguments() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     checkErrorContains(
@@ -705,11 +754,13 @@
         "ruleContext.runfiles(bad_keyword = '')");
   }
 
+  @Test
   public void testNsetContainsList() throws Exception {
     checkErrorContains(
         "sets cannot contain items of type 'list'", "set() + [ruleContext.files.srcs]");
   }
 
+  @Test
   public void testCmdJoinPaths() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     Object result =
@@ -718,6 +769,7 @@
     assertEquals("foo/a.txt:foo/b.img", result);
   }
 
+  @Test
   public void testStructPlusArtifactErrorMessage() throws Exception {
     SkylarkRuleContext ruleContext = createRuleContext("//foo:foo");
     checkErrorContains(
@@ -726,6 +778,7 @@
         "ruleContext.files.tools[0] + struct(a = 1)");
   }
 
+  @Test
   public void testNoSuchProviderErrorMessage() throws Exception {
     checkErrorContains(
         createRuleContext("//foo:bar"),
@@ -733,6 +786,7 @@
         "ruleContext.attr.srcs[0].my_provider");
   }
 
+  @Test
   public void testFilesForRuleConfiguredTarget() throws Exception {
     Object result =
         evalRuleContextCode(createRuleContext("//foo:foo"), "ruleContext.attr.srcs[0].files");
@@ -740,6 +794,7 @@
         "a.txt", ActionsTestUtil.baseNamesOf(((SkylarkNestedSet) result).getSet(Artifact.class)));
   }
 
+  @Test
   public void testFilesForFileConfiguredTarget() throws Exception {
     Object result =
         evalRuleContextCode(createRuleContext("//foo:bar"), "ruleContext.attr.srcs[0].files");
@@ -748,6 +803,7 @@
         ActionsTestUtil.baseNamesOf(((SkylarkNestedSet) result).getSet(Artifact.class)));
   }
 
+  @Test
   public void testCtxStructFieldsCustomErrorMessages() throws Exception {
     checkErrorContains("No attribute 'foo' in attr.", "ruleContext.attr.foo");
     checkErrorContains("No attribute 'foo' in outputs.", "ruleContext.outputs.foo");
@@ -756,18 +812,21 @@
     checkErrorContains("No attribute 'foo' in executable.", "ruleContext.executable.foo");
   }
 
+  @Test
   public void testBinDirPath() throws Exception {
     SkylarkRuleContext ctx = createRuleContext("//foo:bar");
     Object result = evalRuleContextCode(ctx, "ruleContext.configuration.bin_dir.path");
     assertEquals(ctx.getConfiguration().getBinFragment().getPathString(), result);
   }
 
+  @Test
   public void testEmptyLabelListTypeAttrInCtx() throws Exception {
     SkylarkRuleContext ctx = createRuleContext("//foo:baz");
     Object result = evalRuleContextCode(ctx, "ruleContext.attr.srcs");
     assertEquals(MutableList.EMPTY, result);
   }
 
+  @Test
   public void testDefinedMakeVariable() throws Exception {
     SkylarkRuleContext ctx = createRuleContext("//foo:baz");
     String javac = (String) evalRuleContextCode(ctx, "ruleContext.var['JAVAC']");
@@ -776,6 +835,7 @@
     assertEquals("/javac", javac);
   }
 
+  @Test
   public void testCodeCoverageConfigurationAccess() throws Exception {
     SkylarkRuleContext ctx = createRuleContext("//foo:baz");
     boolean coverage =
@@ -832,6 +892,7 @@
     }
   }
 
+  @Test
   public void testStackTraceWithoutOriginalMessage() throws Exception {
     setupThrowFunction(
         new BuiltinFunction("throw") {
@@ -848,6 +909,7 @@
         "throw()");
   }
 
+  @Test
   public void testNoStackTraceOnInterrupt() throws Exception {
     setupThrowFunction(
         new BuiltinFunction("throw") {
@@ -864,6 +926,7 @@
     }
   }
 
+  @Test
   public void testGlobInImplicitOutputs() throws Exception {
     scratch.file("test/glob.bzl",
         "def _impl(ctx):",
diff --git a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java
index 3915b53..9aa0775 100644
--- a/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/skylark/util/SkylarkTestCase.java
@@ -15,12 +15,13 @@
 package com.google.devtools.build.lib.skylark.util;
 
 import static com.google.common.truth.Truth.assertThat;
+import static org.junit.Assert.fail;
 
 import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 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.packages.PackageFactory;
 import com.google.devtools.build.lib.packages.PackageFactory.PackageContext;
 import com.google.devtools.build.lib.rules.SkylarkModules;
@@ -34,37 +35,34 @@
 /**
  * A class to contain the common functionality for Skylark tests.
  */
-public abstract class SkylarkTestCase extends BuildViewTestCase {
+public abstract class SkylarkTestCase extends BuildViewTestCaseForJunit4 {
 
   // We don't have multiple inheritance, so we fake it.
   protected EvaluationTestCase ev;
 
-  protected void setUpEvaluator() throws Exception {
-    ev =
-        new EvaluationTestCase() {
-          @Override
-          public Environment newEnvironment() throws Exception {
-            return Environment.builder(mutability)
-                .setSkylark()
-                .setEventHandler(getEventHandler())
-                .setGlobals(SkylarkModules.GLOBALS)
-                .setLoadingPhase()
-                .build()
-                .setupDynamic(
-                    PackageFactory.PKG_CONTEXT,
-                    // This dummy pkgContext works because no Skylark unit test attempts to actually
-                    // create rules. Creating actual rules is tested in SkylarkIntegrationTest.
-                    new PackageContext(null, null, getEventHandler()));
-          }
-        };
-    ev.setUp();
+  @Before
+  public final void setUpEvaluator() throws Exception {
+    ev = createEvaluationTestCase();
+    ev.initialize();
   }
 
-  @Before
-  @Override
-  protected void setUp() throws Exception {
-    super.setUp();
-    setUpEvaluator();
+  protected EvaluationTestCase createEvaluationTestCase() {
+    return new EvaluationTestCase() {
+      @Override
+      public Environment newEnvironment() throws Exception {
+        return Environment.builder(mutability)
+            .setSkylark()
+            .setEventHandler(getEventHandler())
+            .setGlobals(SkylarkModules.GLOBALS)
+            .setLoadingPhase()
+            .build()
+            .setupDynamic(
+                PackageFactory.PKG_CONTEXT,
+                // This dummy pkgContext works because no Skylark unit test attempts to actually
+                // create rules. Creating actual rules is tested in SkylarkIntegrationTest.
+                new PackageContext(null, null, getEventHandler()));
+      }
+    };
   }
 
   protected Object eval(String... input) throws Exception {
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
index 7c5a582..6cda0b7 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/BaseFunctionTest.java
@@ -52,7 +52,7 @@
 
   private void checkBaseFunction(BaseFunction func, String callExpression, String expectedOutput)
       throws Exception {
-    setUp();
+    initialize();
     update(func.getName(), func);
 
     if (expectedOutput.charAt(0) == '[') { // a tuple => expected to pass
@@ -132,8 +132,8 @@
         "unexpected keyword 'wiz' in call to mixed(*, foo, bar = ?)");
   }
 
-  @Test
   @SuppressWarnings("unchecked")
+  @Test
   public void testKwParam() throws Exception {
     eval("def foo(a, b, c=3, d=4, *args, e, f, g=7, h=8, **kwargs):\n"
         + "  return (a, b, c, d, e, f, g, h, args, kwargs)\n"
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
index be1cf6d..7a10338 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/EvaluationTest.java
@@ -38,8 +38,9 @@
  */
 @RunWith(JUnit4.class)
 public class EvaluationTest extends EvaluationTestCase {
+
   @Before
-  public void setBuildMode() throws Exception {
+  public final void setBuildMode() throws Exception {
     super.setMode(TestMode.BUILD);
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
index eee12f7..a3f71fa 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/MethodLibraryTest.java
@@ -35,9 +35,7 @@
 public class MethodLibraryTest extends EvaluationTestCase {
 
   @Before
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void setFailFast() throws Exception {
     setFailFast(true);
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
index e5d6769..fac46d4 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/ParserTest.java
@@ -43,9 +43,7 @@
   Environment buildEnvironment;
 
   @Before
-  @Override
-  public void setUp() throws Exception {
-    super.setUp();
+  public final void createBuildEnvironment() throws Exception  {
     buildEnvironment = newBuildEnvironment();
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
index 1412c5a..59ba5c3 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/SkylarkEvaluationTest.java
@@ -40,8 +40,9 @@
  */
 @RunWith(JUnit4.class)
 public class SkylarkEvaluationTest extends EvaluationTest {
+
   @Before
-  public void setup() throws Exception {
+  public final void setup() throws Exception {
     setMode(TestMode.SKYLARK);
   }
 
diff --git a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
index 1f7586a..a67a453 100644
--- a/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
+++ b/src/test/java/com/google/devtools/build/lib/syntax/util/EvaluationTestCase.java
@@ -24,7 +24,6 @@
 import com.google.devtools.build.lib.events.EventHandler;
 import com.google.devtools.build.lib.events.EventKind;
 import com.google.devtools.build.lib.events.util.EventCollectionApparatus;
-import com.google.devtools.build.lib.packages.PackageFactory;
 import com.google.devtools.build.lib.syntax.Environment;
 import com.google.devtools.build.lib.syntax.EvalException;
 import com.google.devtools.build.lib.syntax.Expression;
@@ -33,7 +32,6 @@
 import com.google.devtools.build.lib.syntax.ParserInputSource;
 import com.google.devtools.build.lib.syntax.Statement;
 import com.google.devtools.build.lib.testutil.TestMode;
-import com.google.devtools.build.lib.testutil.TestRuleClassProvider;
 
 import org.junit.Before;
 
@@ -46,17 +44,23 @@
 public class EvaluationTestCase {
   private EventCollectionApparatus eventCollectionApparatus =
       new EventCollectionApparatus(EventKind.ALL_EVENTS);
-  private PackageFactory factory;
   private TestMode testMode = TestMode.SKYLARK;
   protected Environment env;
   protected Mutability mutability = Mutability.create("test");
 
   @Before
-  public void setUp() throws Exception {
-    factory = new PackageFactory(TestRuleClassProvider.getRuleClassProvider());
+  public final void initialize() throws Exception {
+    beforeInitialization();
     env = newEnvironment();
   }
 
+  protected void beforeInitialization() throws Exception {
+    // This method exists so that it can be overriden in MakeEnvironmentTest.
+    // The problem is that MakeEnvironmentTest's initialization code (setting up makeEnvBuilder)
+    // needs to run before initialize(), otherwise some tests fail with an NPE.
+    // Consequently, we need this hack to ensure the right order of methods.
+  }
+
   /**
    * Creates a standard Environment for tests in the BUILD language.
    * No PythonPreprocessing, mostly empty mutable Environment.