I am working on spring boot application. I have to write test cases for it. I haven't written test cases before, so someone suggested using spock framework for it. I explored spock and i think it is more related to groovy language.
Can i write spock test cases for my spring application?
If so then could you suggest me a better documentation of "how to use it with spring boot application"?
Yes, you can write spock test cases for your spring application.
Look at the official documentation for an example of Spock testing with Spring Boot
35.3.1 Using Spock to test Spring Boot applications
A simple google search reveals a basic example of Using Spock to test Spring classes.
Spock relies heavily on the Spring's TestContext framework and does this via the @ContextConfiguration annotation. This allows the test specification class to load an application context from one or more locations.
Spring One g2x has a large presentation on Testing Java, Groovy, Spring and Web Applications with Spock.
Groovy and Java can freely be mixed together you can use any Java based library you like, or use Groovy based libraries.
The Spring framework supports Groovy and - not surprisingly - Spring TestContext framework works well with Spock Spock specifications can be run from an IDE just like normal JUnit tests and, last but not least, implementing them is a great opportunity to learn the Groovy language.source
Below are the steps which would help you to write spock test using Spring boot.
@ContextConfiguration(classes = StartApplication.class, loader = SpringApplicationContextLoader.class)
@TestPropertySource(locations = "classpath:application-iTest.properties")
@WebAppConfiguration
@ComponentScan( "com.xyz")
@ActiveProfiles("iTest")
@IntegrationTest("server.port:0")
class TestAuditReport extends Specification{
def Test1(){
given :
when:
then:
1==1
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With