@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()); }
@org.junit.Test public void testExecuteWithTestFailuresAndIgnoreFailures() { configureTask(); test.setIgnoreFailures(true); expectTestsFail(); test.executeTests(); }
@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"))); }
@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"))); }
@org.junit.Test public void notifiesListenerBeforeTest() { final TestClosure closure = context.mock(TestClosure.class); test.beforeTest(HelperUtil.toClosure(closure)); final TestDescriptor testDescriptor = context.mock(TestDescriptor.class); context.checking( new Expectations() { { one(closure).call(testDescriptor); } }); test.getTestListenerBroadcaster().getSource().beforeTest(testDescriptor); }
@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); }
@org.junit.Test public void testExecute() { configureTask(); expectTestsExecuted(); test.executeTests(); }
@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.isIgnoreFailures()); }
@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")); } }
private void configureTask() { test.useTestFramework(testFrameworkMock); test.setTestExecuter(testExecuterMock); test.setTestClassesDir(classesDir); test.setTestResultsDir(resultsDir); test.setTestReportDir(reportDir); test.setClasspath(classpathMock); test.setTestSrcDirs(Collections.<File>emptyList()); }