예제 #1
0
 @org.junit.Test
 public void testExcludes() {
   assertSame(test, test.exclude(TEST_PATTERN_1, TEST_PATTERN_2));
   assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2), test.getExcludes());
   test.exclude(TEST_PATTERN_3);
   assertEquals(toLinkedSet(TEST_PATTERN_1, TEST_PATTERN_2, TEST_PATTERN_3), test.getExcludes());
 }
예제 #2
0
 @org.junit.Test
 public void testExecuteWithTestFailuresAndIgnoreFailures() {
   configureTask();
   test.setIgnoreFailures(true);
   expectTestsFail();
   test.executeTests();
 }
예제 #3
0
  @org.junit.Test
  public void testDisablesParallelExecutionWhenInDebugMode() {
    configureTask();
    test.setDebug(true);
    test.setMaxParallelForks(4);

    assertEquals(1, test.getMaxParallelForks());
  }
예제 #4
0
 @org.junit.Test
 public void testIncludes() {
   assertSame(test, test.include(TEST_PATTERN_1, TEST_PATTERN_2));
   assertEquals(WrapUtil.toList(TEST_PATTERN_1, TEST_PATTERN_2), test.getIncludes());
   test.include(TEST_PATTERN_3);
   assertEquals(
       WrapUtil.toList(TEST_PATTERN_1, TEST_PATTERN_2, TEST_PATTERN_3), test.getIncludes());
 }
예제 #5
0
  @org.junit.Test
  public void testScansForTestClassesInTheTestClassesDir() {
    configureTask();
    test.include("include");
    test.exclude("exclude");

    FileTree classFiles = test.getCandidateClassFiles();
    assertIsDirectoryTree(classFiles, toSet("include"), toSet("exclude"));
  }
예제 #6
0
 @org.junit.Test
 public void testUnmanagedClasspath() {
   List<Object> list1 = WrapUtil.toList("a", new Object());
   assertSame(test, test.unmanagedClasspath(list1.toArray(new Object[list1.size()])));
   assertEquals(list1, test.getUnmanagedClasspath());
   List list2 = WrapUtil.toList(WrapUtil.toList("b", "c"));
   test.unmanagedClasspath(list2.toArray(new Object[list2.size()]));
   assertEquals(GUtil.addLists(list1, GUtil.flatten(list2)), test.getUnmanagedClasspath());
 }
예제 #7
0
파일: TestTest.java 프로젝트: peas/gradle
  @org.junit.Test
  public void testAddsDefaultIncludeAndExcludePatternsWhenTestScanningIsOff() {
    configureTask();
    test.setScanForTestClasses(false);

    ConfigurableFileTree files = (ConfigurableFileTree) test.getCandidateClassFiles();
    assertThat(files.getDir(), equalTo(classesDir));
    assertThat(files.getIncludes(), equalTo(toSet("**/*Tests.class", "**/*Test.class")));
    assertThat(files.getExcludes(), equalTo(toSet("**/Abstract*.class")));
  }
예제 #8
0
 public void testExecuteWithUnspecifiedTestResultsDir() {
   setUpMocks(test);
   test.setTestResultsDir(null);
   try {
     test.execute();
     fail();
   } catch (Exception e) {
     assertThat(e.getCause(), Matchers.instanceOf(InvalidUserDataException.class));
   }
 }
예제 #9
0
파일: TestTest.java 프로젝트: peas/gradle
  @org.junit.Test
  public void testScansForTestClassesInTheTestClassesDir() {
    configureTask();
    test.include("include");
    test.exclude("exclude");

    FileTree classFiles = test.getCandidateClassFiles();
    assertThat(classFiles, instanceOf(ConfigurableFileTree.class));
    ConfigurableFileTree files = (ConfigurableFileTree) classFiles;
    assertThat(files.getDir(), equalTo(classesDir));
    assertThat(files.getIncludes(), equalTo(toSet("include")));
    assertThat(files.getExcludes(), equalTo(toSet("exclude")));
  }
예제 #10
0
  @Before
  public void setUp() {
    super.setUp();
    test = new Test(getProject(), AbstractTaskTest.TEST_TASK_NAME);
    ((AbstractProject) test.getProject()).setProjectDir(TEST_ROOT_DIR);
    context.checking(
        new Expectations() {
          {
            one(testFrameworkMock).initialize(getProject(), test);
          }
        });
    test.useTestFramework(testFrameworkMock);

    if (!TEST_TEST_CLASSES_DIR.exists()) assertTrue(TEST_TEST_CLASSES_DIR.mkdirs());
  }
예제 #11
0
  @org.junit.Test
  public void testExecute() {
    configureTask();
    expectTestsExecuted();

    test.executeTests();
  }
예제 #12
0
  @org.junit.Test
  public void notifiesListenerOfEvents() {
    final TestListener listener = context.mock(TestListener.class);
    test.addTestListener(listener);

    final TestDescriptor testDescriptor = context.mock(TestDescriptor.class);

    context.checking(
        new Expectations() {
          {
            one(listener).beforeSuite(testDescriptor);
          }
        });

    test.getTestListenerBroadcaster().getSource().beforeSuite(testDescriptor);
  }
예제 #13
0
  @org.junit.Test
  public void testExecuteWithNonExistingCompiledTestsDir() {
    setUpMocks(test);
    test.setUnmanagedClasspath(null);
    context.checking(
        new Expectations() {
          {
            allowing(existentDirsFilterMock)
                .checkExistenceAndThrowStopActionIfNot(TEST_TEST_CLASSES_DIR);
            will(throwException(new StopActionException()));
          }
        });
    test.existingDirsFilter = existentDirsFilterMock;

    test.execute();
  }
예제 #14
0
  @org.junit.Test
  public void notifiesListenerBeforeTest() {
    final TestClosure closure = context.mock(TestClosure.class);
    test.beforeTest(TestUtil.toClosure(closure));

    final TestDescriptor testDescriptor = context.mock(TestDescriptor.class);

    context.checking(
        new Expectations() {
          {
            one(closure).call(testDescriptor);
          }
        });

    test.getTestListenerBroadcaster().getSource().beforeTest(testDescriptor);
  }
예제 #15
0
  @org.junit.Test
  public void generatesReport() {
    configureTask();
    expectTestsExecuted();

    final TestReporter testReporter = context.mock(TestReporter.class);
    test.setTestReporter(testReporter);
    context.checking(
        new Expectations() {
          {
            one(testReporter)
                .generateReport(with(any(TestResultsProvider.class)), with(equal(reportDir)));
          }
        });

    test.executeTests();
  }
예제 #16
0
파일: TestTest.java 프로젝트: peas/gradle
  @org.junit.Test
  public void notifiesListenerAfterTest() {
    final TestClosure closure = context.mock(TestClosure.class);
    test.afterTest(HelperUtil.toClosure(closure));

    final TestDescriptor testDescriptor = context.mock(TestDescriptor.class);
    final TestResult result = context.mock(TestResult.class);

    context.checking(
        new Expectations() {
          {
            one(closure).call(testDescriptor);
          }
        });

    test.getTestListenerBroadcaster().getSource().afterTest(testDescriptor, result);
  }
예제 #17
0
 @org.junit.Test
 public void testInit() {
   assertNotNull(test.getTestFramework());
   assertNotNull(test.existingDirsFilter);
   assertNotNull(test.classpathConverter);
   assertNull(test.getTestClassesDir());
   assertNull(test.getConfiguration());
   assertNull(test.getTestResultsDir());
   assertNull(test.getTestReportDir());
   assertNull(test.getIncludes());
   assertNull(test.getExcludes());
   assertNull(test.getUnmanagedClasspath());
   assert test.isStopAtFailuresOrErrors();
 }
예제 #18
0
 @org.junit.Test
 public void testExecuteWithTestFailuresAndContinueWithFailures() {
   setUpMocks(test);
   setExistingDirsFilter();
   test.setStopAtFailuresOrErrors(false);
   context.checking(
       new Expectations() {
         {
           one(testFrameworkMock).prepare(getProject(), test);
           one(testFrameworkMock).getTestClassNames();
           will(returnValue(okTestClassNames));
           one(testFrameworkMock)
               .execute(getProject(), test, okTestClassNames, new ArrayList<String>());
           one(testFrameworkMock).report(getProject(), test);
         }
       });
   test.execute();
 }
예제 #19
0
  private void configureTask() {
    test.useTestFramework(testFrameworkMock);
    test.setTestExecuter(testExecuterMock);

    test.setTestClassesDir(classesDir);
    test.setTestResultsDir(resultsDir);
    test.setBinResultsDir(binResultsDir);
    test.setTestReportDir(reportDir);
    test.setClasspath(classpathMock);
    test.setTestSrcDirs(Collections.<File>emptyList());
  }
예제 #20
0
 @org.junit.Test
 public void testInit() {
   assertThat(test.getTestFramework(), instanceOf(JUnitTestFramework.class));
   assertNull(test.getTestClassesDir());
   assertNull(test.getClasspath());
   assertNull(test.getTestResultsDir());
   assertNull(test.getTestReportDir());
   assertThat(test.getIncludes(), isEmpty());
   assertThat(test.getExcludes(), isEmpty());
   assertFalse(test.getIgnoreFailures());
 }
예제 #21
0
 private void setExistingDirsFilter() {
   context.checking(
       new Expectations() {
         {
           allowing(existentDirsFilterMock)
               .checkExistenceAndThrowStopActionIfNot(TEST_TEST_CLASSES_DIR);
         }
       });
   test.existingDirsFilter = existentDirsFilterMock;
 }
예제 #22
0
 @org.junit.Test
 public void testExecuteWithTestFailuresAndStopAtFailures() {
   configureTask();
   expectTestsFail();
   try {
     test.executeTests();
     fail();
   } catch (GradleException e) {
     assertThat(e.getMessage(), startsWith("There were failing tests. See the report at"));
   }
 }
예제 #23
0
  @org.junit.Test
  public void testSetsTestFrameworkToNullAfterExecution() {
    configureTask();
    // using a jmock generated mock for testFramework does not work here as it is referenced
    // by jmock holds some references.

    test.useTestFramework(
        new TestFramework() {

          public TestFrameworkDetector getDetector() {
            return null;
          }

          public TestFrameworkOptions getOptions() {
            return null;
          }

          public WorkerTestClassProcessorFactory getProcessorFactory() {
            return null;
          }

          public org.gradle.api.Action<WorkerProcessBuilder> getWorkerConfigurationAction() {
            return null;
          }
        });
    context.checking(
        new Expectations() {
          {
            one(testExecuterMock)
                .execute(with(sameInstance(test)), with(notNullValue(TestListenerAdapter.class)));
          }
        });

    WeakReference<TestFramework> weakRef =
        new WeakReference<TestFramework>(test.getTestFramework());
    test.executeTests();

    System.gc(); // explicit gc should normally be avoided, but necessary here.

    assertNull(weakRef.get());
  }
예제 #24
0
 @org.junit.Test(expected = GradleException.class)
 public void testExecuteWithTestFailuresAndStopAtFailures() {
   setUpMocks(test);
   setExistingDirsFilter();
   context.checking(
       new Expectations() {
         {
           one(testFrameworkMock).prepare(getProject(), test);
           one(testFrameworkMock).getTestClassNames();
           will(returnValue(okTestClassNames));
           one(testFrameworkMock)
               .execute(getProject(), test, okTestClassNames, new ArrayList<String>());
         }
       });
   test.execute();
 }
예제 #25
0
  private void setUpMocks(final Test test) {
    test.setTestClassesDir(TEST_TEST_CLASSES_DIR);
    test.setTestResultsDir(TEST_TEST_RESULTS_DIR);
    test.setTestReportDir(TEST_TEST_REPORT_DIR);
    test.setUnmanagedClasspath(TEST_UNMANAGED_CLASSPATH);
    test.setConfiguration(configurationMock);
    test.classpathConverter = classpathConverterMock;

    context.checking(
        new Expectations() {
          {
            allowing(configurationMock).iterator();
            will(returnIterator(TEST_DEPENDENCY_MANAGER_CLASSPATH));
            allowing(classpathConverterMock)
                .createFileClasspath(
                    TEST_ROOT_DIR,
                    GUtil.addLists(
                        WrapUtil.toList(TEST_TEST_CLASSES_DIR),
                        TEST_UNMANAGED_CLASSPATH,
                        TEST_DEPENDENCY_MANAGER_CLASSPATH));
            will(returnValue(TEST_CONVERTED_CLASSPATH));
          }
        });
  }
예제 #26
0
 @org.junit.Test
 public void testGetClasspath() {
   setUpMocks(test);
   assertEquals(TEST_CONVERTED_CLASSPATH, test.getClasspath());
 }