Remove testing support from the CLI

The testing support in the CLI has proven to be more trouble than
it's worth. Our recommendation is that, once an app gets to the stage
of requiring a test suite, it should be converted to a Maven or
Gradle project. This makes it easy to version, publish, deploy etc
using the vast ecosystems of the two build systems.

As part of this change, the dependency management for Spock has been
moved into spring-boot-parent, thereby making it "private". This
allows it to continue to manage the test-only Spock dependency in
spring-boot-test without also managing the version of Spring that is
used by a user's application.

Closes gh-9087
Fixes gh-9043
This commit is contained in:
Andy Wilkinson
2017-05-04 08:52:55 +01:00
parent acda8e647b
commit 329a950bd8
17 changed files with 28 additions and 700 deletions

View File

@@ -40,7 +40,6 @@ import org.springframework.boot.cli.command.OptionParsingCommand;
import org.springframework.boot.cli.command.archive.JarCommand;
import org.springframework.boot.cli.command.grab.GrabCommand;
import org.springframework.boot.cli.command.run.RunCommand;
import org.springframework.boot.cli.command.test.TestCommand;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.util.SocketUtils;
@@ -77,17 +76,6 @@ public class CliTester implements TestRule {
return getOutput();
}
public String test(String... args) throws Exception {
Future<TestCommand> future = submitCommand(new TestCommand(), args);
try {
this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));
return getOutput();
}
catch (Exception ex) {
return getOutput();
}
}
public String grab(String... args) throws Exception {
Future<GrabCommand> future = submitCommand(new GrabCommand(), args);
this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS));

View File

@@ -1,121 +0,0 @@
/*
* Copyright 2012-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.cli;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.boot.cli.command.test.TestCommand;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests to exercise the CLI's test command.
*
* @author Greg Turnquist
* @author Phillip Webb
*/
public class TestCommandIntegrationTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Rule
public CliTester cli = new CliTester("test-samples/");
@Before
public void setUp() throws Exception {
System.setProperty("disableSpringSnapshotRepos", "false");
}
@After
public void tearDown() {
System.clearProperty("disableSpringSnapshotRepos");
}
@Test
public void noTests() throws Throwable {
String output = this.cli.test("book.groovy");
assertThat(output).contains("No tests found");
}
@Test
public void empty() throws Exception {
String output = this.cli.test("empty.groovy");
assertThat(output).contains("No tests found");
}
@Test
public void noFile() throws Exception {
TestCommand command = new TestCommand();
this.thrown.expect(RuntimeException.class);
this.thrown.expectMessage("Can't find nothing.groovy");
command.run("nothing.groovy");
}
@Test
public void appAndTestsInOneFile() throws Exception {
String output = this.cli.test("book_and_tests.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void appInOneFileTestsInAnotherFile() throws Exception {
String output = this.cli.test("book.groovy", "test.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void integrationTest() throws Exception {
String output = this.cli.test("integration.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void integrationAutoConfigEmbeddedTest() throws Exception {
String output = this.cli.test("integration_auto.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void integrationAutoConfigTest() throws Exception {
String output = this.cli.test("integration_auto_test.groovy", "app.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void spockTester() throws Exception {
String output = this.cli.test("spock.groovy");
assertThat(output).contains("OK (1 test)");
}
@Test
public void spockAndJunitTester() throws Exception {
String output = this.cli.test("spock.groovy", "book_and_tests.groovy");
assertThat(output).contains("OK (2 tests)");
}
@Test
public void verifyFailures() throws Exception {
String output = this.cli.test("failures.groovy");
assertThat(output).contains("Tests run: 5, Failures: 3");
}
}

View File

@@ -1,47 +0,0 @@
/*
* Copyright 2012-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.cli.command.test;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import static org.hamcrest.Matchers.equalTo;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Tests for {@link TestRunner}.
*
* @author Andy Wilkinson
*/
public class TestRunnerTests {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void exceptionMessageWhenSourcesContainsNoClasses() throws Exception {
TestRunnerConfiguration configuration = mock(TestRunnerConfiguration.class);
given(configuration.getClasspath()).willReturn(new String[0]);
this.thrown.expect(RuntimeException.class);
this.thrown.expectMessage(equalTo("No classes found in '[foo, bar]'"));
new TestRunner(configuration, new String[] { "foo", "bar" }, new String[0])
.compileAndRunTests();
}
}