ナイスディスカッション!私はJGivenを知りませんでしたが、調べてみます。
さらに、私はCOLA Testsの作成者です。これは、完全な gherkin 構文 (Cucumber とまったく同じ) をサポートする新しいフレームワークです。特に JBehave と比較すると、セットアップが非常に簡単で、JUnit ランナーを必要としません。
基本的には、使い慣れたライブラリを使用するだけです!
以下は、Spring Controller テストの例です (ストーリーはファイルからロードできます)。
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = { WebAppContext.class })
public class HelloWorldControllerTest extends BaseColaTest {
private final String stories =
"Feature: Introduce REST endpoint\n"
+ "Scenario: Should say hello\n"
+ "Given a web endpoint\n"
+ "When hit by a get request\n"
+ "Then the HTTP status will be OK\n"
+ "And the body will say hello world";
@Resource
private WebApplicationContext webApplicationContext;
private MockMvc mockMvc;
private ResultActions result;
@Given("a web endpoint")
public void given() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@When("hit by a get request")
public void when() throws Exception {
result = mockMvc.perform(get("/helloWorld"));
}
@Then("the HTTP status will be OK")
public void thenOk() throws Exception {
result.andExpect(status().isOk());
}
@Then("the body will say hello world")
public void thenHello() throws Exception {
result.andExpect(content().string("Hello World!"));
}
}