You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This means that `spock-spring` will startup spring context (not junit extension!),
382
+
but all other junit extensions will work (essentially, it "applies" `@IngoreJunitExtensions(SpringExtension)` automatically).
383
+
384
+
There would be a new message in log, indicating that you're using pure spock spring support (and an alternative is possible):
385
+
386
+
```
387
+
[spock-junit6] Spring junit extension disabled (org.springframework.test.context.junit.jupiter.SpringExtension) because spock-spring detected and so it will handle spring context initialization (all other junit extensions will work). If you want to run spring as junit extension, use spock-core only (without spock-spring).
388
+
```
389
+
390
+
The main benefit is that you **could use** spock mocking (`@SpringBean`) and other spock features.
391
+
392
+
IMPORTANT: In case of problems (spring has many test annotations, and I did not check all of them),
393
+
use `@DebugJunitExtensions` to see what extensions are actually used and `@IgnoreJunitExtensions` to ignore
394
+
conflicting extensions (assuming spock-spring already implements them natively).
395
+
Or just migrate to `spock-core` and use pure junit spring extensions (see below).
396
+
397
+
398
+
#### Pure junit way
399
+
400
+
If you want to use the native junit spring extension, then don't apply `spock-spring` (use `spock-core` only):
Note that [spock-spring module](https://spockframework.org/spock/docs/2.3/modules.html#_spring_module)
329
-
**should not be used** together with spock-junit5 for spring-boot tests!
330
-
Spock-junit5 would activate native spring junit5 extensions **the same way** as in raw junit
407
+
In this case, the native junit spring extension will be used.
408
+
409
+
NOTE: in this case, you **would not** be able to use spock mocking (`@SpringBean`), instead you'll have
410
+
to use [mockito alternatives](https://docs.spring.io/spring-boot/reference/testing/spring-boot-applications.html#testing.spring-boot-applications.mocking-beans)
411
+
(`@MockitoBean` and `@MockitoSpyBean`).
331
412
332
-
Example MVC test (based
333
-
on [this example](https://github.com/mkyong/spring-boot/blob/master/spring-boot-hello-world/src/test/java/com/mkyong/HelloControllerTests.java)):
413
+
#### MVC test example
414
+
415
+
Example MVC test (based on [this example](https://github.com/mkyong/spring-boot/blob/master/spring-boot-hello-world/src/test/java/com/mkyong/HelloControllerTests.java)):
334
416
335
417
```groovy
336
418
@SpringBootTest
@@ -353,13 +435,12 @@ class ControllerTest extends Specification {
353
435
}
354
436
```
355
437
356
-
Example JPA test (based
357
-
on [this example](https://github.com/mkyong/spring-boot/blob/master/spring-data-jpa/src/test/java/com/mkyong/BookRepositoryTest.java)):
438
+
Example JPA test (based on [this example](https://github.com/mkyong/spring-boot/blob/master/spring-data-jpa/src/test/java/com/mkyong/BookRepositoryTest.java)):
358
439
359
440
```groovy
360
441
@DataJpaTest
361
442
class BootTest extends Specification {
362
-
443
+
363
444
@Autowired
364
445
TestEntityManager testEM
365
446
@Autowired
@@ -461,9 +542,7 @@ class SpockExtensionImpl implements IAnnotationDrivenExtension<SpockExtension> {
461
542
spec.allFixtureMethods*.addInterceptor new I('fixture method')
462
543
}
463
544
464
-
static class I implements IMethodInterceptor {
465
-
...
466
-
}
545
+
static class I implements IMethodInterceptor { ... }
0 commit comments