Skip to content

Commit c380aaa

Browse files
committed
Make Spock specs atomic if certain criteria are met
1 parent b66b56d commit c380aaa

13 files changed

+773
-30
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<pitest.version>1.14.2</pitest.version>
2727
<cucumber.version>5.0.0</cucumber.version>
2828
<spock.version>2.3-groovy-4.0</spock.version>
29+
<junit4.version>4.13.2</junit4.version>
2930
<groovy.version>4.0.11</groovy.version>
3031
</properties>
3132

@@ -199,6 +200,12 @@
199200
<artifactId>spock-core</artifactId>
200201
<scope>test</scope>
201202
</dependency>
203+
<dependency>
204+
<groupId>junit</groupId>
205+
<artifactId>junit</artifactId>
206+
<version>${junit4.version}</version>
207+
<scope>test</scope>
208+
</dependency>
202209
</dependencies>
203210

204211
<build>

src/main/java/org/pitest/junit5/JUnit5TestUnitFinder.java

Lines changed: 361 additions & 21 deletions
Large diffs are not rendered by default.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.jupiter.api.AfterAll
20+
import spock.lang.Specification
21+
22+
class TestSpecWithAfterAll extends Specification {
23+
@AfterAll
24+
static afterAll() {
25+
}
26+
27+
def test() {
28+
expect:
29+
true
30+
31+
where:
32+
i << (1..2)
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.AfterClass
20+
import spock.lang.Specification
21+
22+
class TestSpecWithAfterClass extends Specification {
23+
@AfterClass
24+
static afterClass() {
25+
}
26+
27+
def test() {
28+
expect:
29+
true
30+
31+
where:
32+
i << (1..2)
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.jupiter.api.BeforeAll
20+
import spock.lang.Specification
21+
22+
class TestSpecWithBeforeAll extends Specification {
23+
@BeforeAll
24+
static beforeAll() {
25+
}
26+
27+
def test() {
28+
expect:
29+
true
30+
31+
where:
32+
i << (1..2)
33+
}
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.BeforeClass
20+
import spock.lang.Specification
21+
22+
class TestSpecWithBeforeClass extends Specification {
23+
@BeforeClass
24+
static beforeClass() {
25+
}
26+
27+
def test() {
28+
expect:
29+
true
30+
31+
where:
32+
i << (1..2)
33+
}
34+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.ClassRule
20+
import spock.lang.Specification
21+
22+
class TestSpecWithClassRuleField extends Specification {
23+
@ClassRule
24+
public static classRule
25+
26+
def test() {
27+
expect:
28+
true
29+
30+
where:
31+
i << (1..2)
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import org.junit.ClassRule
20+
import spock.lang.Specification
21+
22+
class TestSpecWithClassRuleMethod extends Specification {
23+
@ClassRule
24+
static afterClass() {
25+
}
26+
27+
def test() {
28+
expect:
29+
true
30+
31+
where:
32+
i << (1..2)
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import spock.lang.Shared
20+
import spock.lang.Specification
21+
22+
class TestSpecWithSetupSpecWithoutShared extends Specification {
23+
static fail = true
24+
25+
def setupSpec() {
26+
fail = false
27+
}
28+
29+
def aTest() {
30+
expect:
31+
!fail
32+
}
33+
34+
def anotherTest() {
35+
expect:
36+
!fail
37+
}
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2023 Björn Kautler
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.pitest.junit5.repository
18+
19+
import spock.lang.Shared
20+
import spock.lang.Specification
21+
22+
class TestSpecWithShared extends Specification {
23+
@Shared
24+
foo
25+
26+
def test() {
27+
expect:
28+
true
29+
30+
where:
31+
i << (1..2)
32+
}
33+
}

0 commit comments

Comments
 (0)