Skip to content

Commit

Permalink
Nested steps not reported with jgiven spring
Browse files Browse the repository at this point in the history
  • Loading branch information
s-bortolussi committed Dec 1, 2016
1 parent 59983ff commit 8b827e4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<HelloStage> {

@Rule
public OutputCapture capture = new OutputCapture();

@Test
public void nested_test() throws Exception {
when().get( "/" );
then().I_should_get_home_page();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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!" );
}
}

1 comment on commit 8b827e4

@s-bortolussi
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this specific example, nested steps are not reported in the output logs.
Actual test output logs contain

 Nested test

   When get "/"
   Then I should get home page

But expected test output log should contain

 Nested test

   When get "/"
   Then I should get home page
          the status is OK (200)
         And the content is "Greetings from JGiven!"

Please sign in to comment.