Skip to content

Commit

Permalink
Improve speed of spring-test build
Browse files Browse the repository at this point in the history
- 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
sbrannen committed Jan 11, 2013
1 parent c1fe3c0 commit 5b147bf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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. */
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 5b147bf

Please sign in to comment.