Permalink
Browse files

Improve speed of spring-test build

- Now excluding *TestSuite classes from the JUnit test task.
- Renamed SpringJUnit4SuiteTests to SpringJUnit4TestSuite so that it is
  no longer executed in the build.
- Reduced sleep time in various timing related tests.
  • Loading branch information...
1 parent c1fe3c0 commit 5b147bfba8d5d5837b96357a52867e433137f64b @sbrannen sbrannen committed Jan 11, 2013
View
@@ -655,7 +655,7 @@ project("spring-test") {
dependsOn testNG
useJUnit()
// "TestCase" classes are run by other test classes, not the build.
- exclude "**/*TestCase.class"
+ exclude(["**/*TestCase.class", "**/*TestSuite.class"])
}
dependencies {
@@ -29,6 +29,7 @@
import org.junit.runners.JUnit4;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
+import org.springframework.context.annotation.Configuration;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -179,9 +180,14 @@ public static void verifyFinalCacheState() {
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class,
DirtiesContextTestExecutionListener.class })
- @ContextConfiguration("/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml")
+ @ContextConfiguration
public static abstract class BaseTestCase {
+ @Configuration
+ static class Config {
+ /* no beans */
+ }
+
@Autowired
protected ApplicationContext applicationContext;
@@ -156,34 +156,34 @@ public void repeatedFiveTimes() throws Exception {
public static final class TimedRepeatedTestCase extends AbstractRepeatedTestCase {
@Test
- @Timed(millis = 10000)
+ @Timed(millis = 1000)
@Repeat(5)
public void repeatedFiveTimesButDoesNotExceedTimeout() throws Exception {
incrementInvocationCount();
}
@Test
- @Timed(millis = 100)
+ @Timed(millis = 10)
@Repeat(1)
public void singleRepetitionExceedsTimeout() throws Exception {
incrementInvocationCount();
- Thread.sleep(250);
+ Thread.sleep(15);
}
@Test
- @Timed(millis = 200)
+ @Timed(millis = 20)
@Repeat(4)
public void firstRepetitionOfManyExceedsTimeout() throws Exception {
incrementInvocationCount();
- Thread.sleep(250);
+ Thread.sleep(25);
}
@Test
- @Timed(millis = 1000)
+ @Timed(millis = 100)
@Repeat(10)
public void collectiveRepetitionsExceedTimeout() throws Exception {
incrementInvocationCount();
- Thread.sleep(150);
+ Thread.sleep(11);
}
}
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-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.
@@ -42,15 +42,16 @@
/**
* JUnit test suite for tests involving {@link SpringJUnit4ClassRunner} and the
- * <em>Spring TestContext Framework</em>.
+ * <em>Spring TestContext Framework</em>; only intended to be run manually as a
+ * convenience.
*
* <p>This test suite serves a dual purpose of verifying that tests run with
* {@link SpringJUnit4ClassRunner} can be used in conjunction with JUnit's
* {@link Suite} runner.
*
* <p>Note that tests included in this suite will be executed at least twice if
- * run from an automated build process, test runner, etc. that is configured to
- * run tests based on a &quot;*Tests.class&quot; pattern match.
+ * run from an automated build process, test runner, etc. that is not configured
+ * to exclude tests based on a &quot;*TestSuite.class&quot; pattern match.
*
* @author Sam Brannen
* @since 2.5
@@ -104,6 +105,6 @@
TimedTransactionalSpringRunnerTests.class,//
HibernateSessionFlushingTests.class //
})
-public class SpringJUnit4SuiteTests {
+public class SpringJUnit4TestSuite {
/* this test case consists entirely of tests loaded as a suite. */
}
@@ -76,16 +76,16 @@ public void testSpringTimeoutWithNoOp() {
}
// Should Fail due to timeout.
- @Test(timeout = 200)
+ @Test(timeout = 10)
public void testJUnitTimeoutWithOneSecondWait() throws Exception {
- Thread.sleep(1000);
+ Thread.sleep(20);
}
// Should Fail due to timeout.
@Test
- @Timed(millis = 200)
+ @Timed(millis = 10)
public void testSpringTimeoutWithOneSecondWait() throws Exception {
- Thread.sleep(1000);
+ Thread.sleep(20);
}
// Should Fail due to duplicate configuration.

2 comments on commit 5b147bf

Contributor

cbeams replied Jan 14, 2013

Thanks, @sbrannen. Just noted that the copyright headers haven't been updated to 2013. Also, a minor point, but the the test methods named "OneSecond" aren't exactly accurate anymore now that the timeouts have been reduced from 1000ms to 20ms.

Member

sbrannen replied Jan 14, 2013

Good catch! I'll fix that ASAP.

Please sign in to comment.