spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 734 forks source link

Issue with the Junit Rest Documentation with the spring docs 2.0.5.Release and spring boot version 2.7.6 version in controller testcases #929

Closed DarthVader3011 closed 4 months ago

DarthVader3011 commented 4 months ago
@SpringBoooTest(WebEnvironment=SpringBootTest.WebEnvironment.Random.Port)
@AutoConfigureMockMvc
class testSpec extends Specification{

    @Autowired 
    private WebAPplicationContext context;

    @Rule 
    JunitRestDocumentation junit = new JunitRestDocumentation()

    @AutoWired
    private MockMvc mockMvc

    void setup{
        this.mockMvc = MockMvcBuilder.webAppContextsetup(this.context)
            .apply(documentationConfiguration(junitRestDocumenation).operationPreprocessors()
            .withRequestDefault("").withResponseDefaule("").build()
    }

    //some test cases
    def "" () {

    }

}

When I execute the above test case which in Spock groovy, the Junit REST documentation object is unable to initialize the context, leading to a null pointer exception.The junitRestDocumenation object contains a ManualRestDocumentaion which has outputDir and context ..so i am getting context as null ...

The Asciidoctorj version i am using is 2.4.0

wilkinsona commented 4 months ago

I suspect Spock isn't calling the rule. Does https://spockframework.org/spock/docs/2.3/migration_guide.html#_junit_4_support help?

DarthVader3011 commented 4 months ago

thanks, adding spock-junit4 dependency in gradle it worked. Thanks Wilkinsona cheers