Add 'spring test [files]' command to compile and test code automatically
- Look for JUnit test symbols, and add JUnit automatically - Look for Spock test symbols, and add Spock automatically - Based on what test libraries were used, invoke relevant embedded testers and accumulate results - Make it so that multiple testers can be invoked through a single 'test' command - Print out total results and write out detailed trace errors in results.txt - Update based on the new artifact resolution mechanism
This commit is contained in:
@@ -1,21 +1,18 @@
|
||||
package org.springframework.boot.cli;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.cli.Command;
|
||||
import org.springframework.boot.cli.NoSuchCommandException;
|
||||
import org.springframework.boot.cli.SpringCli;
|
||||
import org.springframework.boot.cli.SpringCli.NoArgumentsException;
|
||||
import org.springframework.boot.cli.SpringCli.NoHelpCommandArgumentsException;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2012-2013 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.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.cli.command.CleanCommand;
|
||||
import org.springframework.boot.cli.command.TestCommand;
|
||||
import org.springframework.boot.cli.command.tester.TestResults;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Integration tests to exercise the CLI's test command.
|
||||
*
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class TestCommandIntegrationTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void cleanGrapes() throws Exception {
|
||||
GrapesCleaner.cleanIfNecessary();
|
||||
// System.setProperty("ivy.message.logger.level", "3");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
System.setProperty("disableSpringSnapshotRepos", "true");
|
||||
new CleanCommand().run("org.springframework");
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() {
|
||||
System.clearProperty("disableSpringSnapshotRepos");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noTests() throws Throwable {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/book.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(0, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empty() throws Exception {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/empty.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(0, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void noFile() throws Exception {
|
||||
try {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/nothing.groovy");
|
||||
} catch (RuntimeException e) {
|
||||
assertEquals("Can't find testscripts/nothing.groovy", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appAndTestsInOneFile() throws Exception {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/book_and_tests.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(1, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appInOneFileTestsInAnotherFile() throws Exception {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/book.groovy", "testscripts/test.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(1, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spockTester() throws Exception {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/spock.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(1, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void spockAndJunitTester() throws Exception {
|
||||
TestCommand command = new TestCommand();
|
||||
command.run("testscripts/spock.groovy", "testscripts/book_and_tests.groovy");
|
||||
TestResults results = command.getResults();
|
||||
assertEquals(2, results.getRunCount());
|
||||
assertEquals(0, results.getFailureCount());
|
||||
assertTrue(results.wasSuccessful());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,8 +22,6 @@ import groovy.lang.Script;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.cli.GrapesCleaner;
|
||||
import org.springframework.boot.cli.command.OptionHandler;
|
||||
import org.springframework.boot.cli.command.ScriptCommand;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
|
||||
Reference in New Issue
Block a user