Skip to content

Commit 5b147bf

Browse files
committed
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.
1 parent c1fe3c0 commit 5b147bf

File tree

5 files changed

+25
-18
lines changed

5 files changed

+25
-18
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ project("spring-test") {
655655
dependsOn testNG
656656
useJUnit()
657657
// "TestCase" classes are run by other test classes, not the build.
658-
exclude "**/*TestCase.class"
658+
exclude(["**/*TestCase.class", "**/*TestSuite.class"])
659659
}
660660

661661
dependencies {

spring-test/src/test/java/org/springframework/test/context/ClassLevelDirtiesContextTests.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.junit.runners.JUnit4;
3030
import org.springframework.beans.factory.annotation.Autowired;
3131
import org.springframework.context.ApplicationContext;
32+
import org.springframework.context.annotation.Configuration;
3233
import org.springframework.test.annotation.DirtiesContext;
3334
import org.springframework.test.annotation.DirtiesContext.ClassMode;
3435
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -179,9 +180,14 @@ public static void verifyFinalCacheState() {
179180
@RunWith(SpringJUnit4ClassRunner.class)
180181
@TestExecutionListeners( { DependencyInjectionTestExecutionListener.class,
181182
DirtiesContextTestExecutionListener.class })
182-
@ContextConfiguration("/org/springframework/test/context/junit4/SpringJUnit4ClassRunnerAppCtxTests-context.xml")
183+
@ContextConfiguration
183184
public static abstract class BaseTestCase {
184185

186+
@Configuration
187+
static class Config {
188+
/* no beans */
189+
}
190+
185191
@Autowired
186192
protected ApplicationContext applicationContext;
187193

spring-test/src/test/java/org/springframework/test/context/junit4/RepeatedSpringRunnerTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,34 +156,34 @@ public void repeatedFiveTimes() throws Exception {
156156
public static final class TimedRepeatedTestCase extends AbstractRepeatedTestCase {
157157

158158
@Test
159-
@Timed(millis = 10000)
159+
@Timed(millis = 1000)
160160
@Repeat(5)
161161
public void repeatedFiveTimesButDoesNotExceedTimeout() throws Exception {
162162
incrementInvocationCount();
163163
}
164164

165165
@Test
166-
@Timed(millis = 100)
166+
@Timed(millis = 10)
167167
@Repeat(1)
168168
public void singleRepetitionExceedsTimeout() throws Exception {
169169
incrementInvocationCount();
170-
Thread.sleep(250);
170+
Thread.sleep(15);
171171
}
172172

173173
@Test
174-
@Timed(millis = 200)
174+
@Timed(millis = 20)
175175
@Repeat(4)
176176
public void firstRepetitionOfManyExceedsTimeout() throws Exception {
177177
incrementInvocationCount();
178-
Thread.sleep(250);
178+
Thread.sleep(25);
179179
}
180180

181181
@Test
182-
@Timed(millis = 1000)
182+
@Timed(millis = 100)
183183
@Repeat(10)
184184
public void collectiveRepetitionsExceedTimeout() throws Exception {
185185
incrementInvocationCount();
186-
Thread.sleep(150);
186+
Thread.sleep(11);
187187
}
188188
}
189189

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,15 +42,16 @@
4242

4343
/**
4444
* JUnit test suite for tests involving {@link SpringJUnit4ClassRunner} and the
45-
* <em>Spring TestContext Framework</em>.
45+
* <em>Spring TestContext Framework</em>; only intended to be run manually as a
46+
* convenience.
4647
*
4748
* <p>This test suite serves a dual purpose of verifying that tests run with
4849
* {@link SpringJUnit4ClassRunner} can be used in conjunction with JUnit's
4950
* {@link Suite} runner.
5051
*
5152
* <p>Note that tests included in this suite will be executed at least twice if
52-
* run from an automated build process, test runner, etc. that is configured to
53-
* run tests based on a &quot;*Tests.class&quot; pattern match.
53+
* run from an automated build process, test runner, etc. that is not configured
54+
* to exclude tests based on a &quot;*TestSuite.class&quot; pattern match.
5455
*
5556
* @author Sam Brannen
5657
* @since 2.5
@@ -104,6 +105,6 @@
104105
TimedTransactionalSpringRunnerTests.class,//
105106
HibernateSessionFlushingTests.class //
106107
})
107-
public class SpringJUnit4SuiteTests {
108+
public class SpringJUnit4TestSuite {
108109
/* this test case consists entirely of tests loaded as a suite. */
109110
}

spring-test/src/test/java/org/springframework/test/context/junit4/TimedSpringRunnerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ public void testSpringTimeoutWithNoOp() {
7676
}
7777

7878
// Should Fail due to timeout.
79-
@Test(timeout = 200)
79+
@Test(timeout = 10)
8080
public void testJUnitTimeoutWithOneSecondWait() throws Exception {
81-
Thread.sleep(1000);
81+
Thread.sleep(20);
8282
}
8383

8484
// Should Fail due to timeout.
8585
@Test
86-
@Timed(millis = 200)
86+
@Timed(millis = 10)
8787
public void testSpringTimeoutWithOneSecondWait() throws Exception {
88-
Thread.sleep(1000);
88+
Thread.sleep(20);
8989
}
9090

9191
// Should Fail due to duplicate configuration.

0 commit comments

Comments
 (0)