From 8b827e4abb49eff46185be76b5cf674f98773e5b Mon Sep 17 00:00:00 2001 From: Sebastien Bortolussi Date: Thu, 1 Dec 2016 17:39:57 +0100 Subject: [PATCH] Nested steps not reported with jgiven spring [#259] --- .../HelloControllerNestedStepTest.java | 36 +++++++++++++++++++ .../jgiven/example/springboot/HelloStage.java | 7 ++++ 2 files changed, 43 insertions(+) create mode 100644 examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloControllerNestedStepTest.java diff --git a/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloControllerNestedStepTest.java b/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloControllerNestedStepTest.java new file mode 100644 index 0000000000..392ccc7bc5 --- /dev/null +++ b/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloControllerNestedStepTest.java @@ -0,0 +1,36 @@ +package com.tngtech.jgiven.example.springboot; + +import com.tngtech.jgiven.annotation.As; +import com.tngtech.jgiven.annotation.JGivenConfiguration; +import com.tngtech.jgiven.integration.spring.SimpleSpringScenarioTest; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.OutputCapture; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.http.HttpStatus; +import org.springframework.mock.web.MockServletContext; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.web.WebAppConfiguration; + +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.MatcherAssert.assertThat; + +@RunWith( SpringJUnit4ClassRunner.class ) +@SpringApplicationConfiguration( classes = { MockServletContext.class, HelloTestContext.class } ) +@WebAppConfiguration +@JGivenConfiguration( HelloJGivenConfiguration.class ) +public class HelloControllerNestedStepTest extends SimpleSpringScenarioTest { + + @Rule + public OutputCapture capture = new OutputCapture(); + + @Test + public void nested_test() throws Exception { + when().get( "/" ); + then().I_should_get_home_page(); + } + +} \ No newline at end of file diff --git a/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloStage.java b/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloStage.java index ee3f2c96d4..c5c8a98283 100644 --- a/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloStage.java +++ b/examples/spring-boot/src/test/java/com/tngtech/jgiven/example/springboot/HelloStage.java @@ -4,6 +4,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import com.tngtech.jgiven.annotation.NestedSteps; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -46,4 +47,10 @@ public HelloStage the_content_is( @Quoted String content ) throws Exception { mvcResult.andExpect( content().string( equalTo( content ) ) ); return this; } + + @NestedSteps + public HelloStage I_should_get_home_page() throws Exception { + return the_status_is( HttpStatus.OK ) + .and().the_content_is( "Greetings from JGiven!" ); + } }