Add @LongRunningTest JUnit 5 condition
* Add docs about `@LongRunningTest`
This commit is contained in:
committed by
Gary Russell
parent
59860c0a4b
commit
1595462ce7
@@ -32,10 +32,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -56,8 +53,7 @@ import org.springframework.integration.stomp.event.StompExceptionEvent;
|
||||
import org.springframework.integration.stomp.event.StompIntegrationEvent;
|
||||
import org.springframework.integration.stomp.event.StompReceiptEvent;
|
||||
import org.springframework.integration.stomp.event.StompSessionConnectedEvent;
|
||||
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
|
||||
import org.springframework.integration.test.support.LongRunningIntegrationTest;
|
||||
import org.springframework.integration.test.condition.LongRunningTest;
|
||||
import org.springframework.integration.websocket.TomcatWebSocketTestServer;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -75,8 +71,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.web.socket.client.WebSocketClient;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
|
||||
@@ -95,19 +90,11 @@ import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
*
|
||||
* @since 4.2
|
||||
*/
|
||||
@ContextConfiguration(classes = StompMessageHandlerWebSocketIntegrationTests.ContextConfiguration.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig(StompMessageHandlerWebSocketIntegrationTests.ContextConfiguration.class)
|
||||
@LongRunningTest
|
||||
@DirtiesContext
|
||||
public class StompMessageHandlerWebSocketIntegrationTests {
|
||||
|
||||
@ClassRule
|
||||
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
|
||||
|
||||
@Rule
|
||||
public Log4j2LevelAdjuster adjuster =
|
||||
Log4j2LevelAdjuster.trace()
|
||||
.categories("org.springframework", "org.springframework.integration.stomp");
|
||||
|
||||
@Value("#{server.serverContext}")
|
||||
private ApplicationContext serverContext;
|
||||
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2018 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.integration.test.condition;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.jupiter.api.condition.EnabledIf;
|
||||
|
||||
/**
|
||||
* JUnit Jupiter condition to prevent long running tests from running on every build;
|
||||
* set environment variable {@code RUN_LONG_INTEGRATION_TESTS} on a CI nightly build to ensure coverage.
|
||||
*
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 5.1
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@EnabledIf(LongRunningTest.LONG_RUNNING_SCRIPT)
|
||||
public @interface LongRunningTest {
|
||||
|
||||
String LONG_RUNNING_SCRIPT =
|
||||
"systemEnvironment.get('RUN_LONG_INTEGRATION_TESTS') == 'true' ||" +
|
||||
" systemProperty.get('RUN_LONG_INTEGRATION_TESTS') == 'true'";
|
||||
|
||||
}
|
||||
@@ -168,12 +168,18 @@ The `org.springframework.integration.test.support` package contains various abst
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/AbstractRequestResponseScenarioTests.html[`AbstractRequestResponseScenarioTests`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/AbstractResponseValidator.html[`AbstractResponseValidator`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/LogAdjustingTestSupport.html[`LogAdjustingTestSupport`] (Deprecated)
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/LongRunningIntegrationTest.html[`LongRunningIntegrationTest`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/MessageValidator.html[`MessageValidator`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/PayloadValidator.html[`PayloadValidator`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/RequestResponseScenario.html[`RequestResponseScenario`]
|
||||
* https://docs.spring.io/spring-integration/api/org/springframework/integration/test/support/SingleRequestResponseScenarioTests.html[`SingleRequestResponseScenarioTests`]
|
||||
|
||||
[[test-junit-rules]]
|
||||
==== JUnit Rules and Conditions
|
||||
|
||||
The `LongRunningIntegrationTest` JUnit 4 test rule is present to indicate if test should be run if `RUN_LONG_INTEGRATION_TESTS` environment or system property is set to `true`.
|
||||
Otherwise it is skipped.
|
||||
For the same reason since version 5.1, a `@LongRunningTest` conditional annotation is provided for JUnit 5 tests.
|
||||
|
||||
==== Hamcrest and Mockito Matchers
|
||||
|
||||
The `org.springframework.integration.test.matcher` package contains several `Matcher` implementations to assert `Message` and its properties in unit tests.
|
||||
@@ -220,6 +226,8 @@ assertThat(channel.send(message), is(false));
|
||||
----
|
||||
====
|
||||
|
||||
|
||||
|
||||
[[test-context]]
|
||||
=== Spring Integration and the Test Context
|
||||
|
||||
|
||||
@@ -26,6 +26,13 @@ Also Kotlin lambdas now can be used for handler and source methods.
|
||||
|
||||
See <<functions-support>>.
|
||||
|
||||
[[x5.1-LongRunningTest]]
|
||||
==== `@LongRunningTest`
|
||||
|
||||
A JUnit 5 `@LongRunningTest` conditional annotation is provided to check the environment or system properties for the `RUN_LONG_INTEGRATION_TESTS` entry with the value of `true` to determine if test should be run or skipped.
|
||||
|
||||
See <<test-junit-rules>>.
|
||||
|
||||
[[x5.1-general]]
|
||||
=== General Changes
|
||||
|
||||
|
||||
Reference in New Issue
Block a user