Browse Source
Previously, TestTypeExcludeFilter only looked for JUnit 4 class and method annotations when determining if a class was a test class. As a result, if an application was using JUnit Jupiter, its test classes would not be exluded during component scanning. This commit expands TestTypeExcludeFilter to also identify classes using JUnit Jupiter. This includes classes (meta-)annotated with @ExtendWith and methods (meta-)annotated with @Testable. The later provides detection of Jupiter's @Test, @TestFactory, and @RepeatedTest annotations all of which are meta-annotated with @Testable. Closes gh-6898pull/9635/head
7 changed files with 164 additions and 5 deletions
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
/* |
||||
* Copyright 2012-2016 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.test.context.filter; |
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith; |
||||
|
||||
import org.springframework.context.annotation.Configuration; |
||||
import org.springframework.test.context.junit.jupiter.SpringExtension; |
||||
|
||||
@ExtendWith(SpringExtension.class) |
||||
public abstract class AbstractJupiterTestWithConfigAndExtendWith { |
||||
|
||||
@Configuration |
||||
static class Config { |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* Copyright 2012-2017 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.test.context.filter; |
||||
|
||||
import org.junit.jupiter.api.RepeatedTest; |
||||
|
||||
public class JupiterRepeatedTestExample { |
||||
|
||||
@RepeatedTest(5) |
||||
public void repeatedTest() { |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
/* |
||||
* Copyright 2012-2017 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.test.context.filter; |
||||
|
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class JupiterTestExample { |
||||
|
||||
@Test |
||||
public void repeatedTest() { |
||||
|
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,35 @@
@@ -0,0 +1,35 @@
|
||||
/* |
||||
* Copyright 2012-2017 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.test.context.filter; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.Collection; |
||||
|
||||
import org.junit.jupiter.api.DynamicNode; |
||||
import org.junit.jupiter.api.DynamicTest; |
||||
import org.junit.jupiter.api.TestFactory; |
||||
|
||||
public class JupiterTestFactoryExample { |
||||
|
||||
@TestFactory |
||||
public Collection<DynamicNode> testFactory() { |
||||
return Arrays.asList(DynamicTest.dynamicTest("Some dynamic test", () -> { |
||||
// Test
|
||||
})); |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue