2017-03-15 14 views
5

Ben Salatalık testler içinde MockMvc kullanmayı deneyin ama hiçbir bahar bağımlılıkları çözülür.@RunWith (Cucumber.class) ve @Autowired MockMvc

@RunWith(Cucumber.class) 
@CucumberOptions(format = "pretty", features = "src/test/resources/features"}) 
@SpringBootTest 
public class CucumberTest { 

} 

salatalık özelliğini

çalıştırmak Ve adımları için bu sınıf:

@WebMvcTest(VersionController.class) 
@AutoConfigureWebMvc 
public class VersionControllerSteps { 

    @Autowired 
    private MockMvc mvc; 

    private MvcResult result; 

    @When("^the client calls /version$") 
    public void the_client_issues_GET_version() throws Throwable { 
     result = mvc.perform(get("/version")).andDo(print()).andReturn(); 
    } 

    @Then("^the client receives status code of (\\d+)$") 
    public void the_client_receives_status_code_of(int statusCode) throws Throwable { 
     assertThat(result.getResponse().getStatus()).isEqualTo(statusCode); 
    } 

    @And("^the client receives server version (.+)$") 
    public void the_client_receives_server_version_body(String version) throws Throwable { 
     assertThat(result.getResponse().getContentAsString()).isEqualTo(version); 
    } 
} 

ama bu atış istisna:

java.lang.NullPointerException 
at com.example.rest.VersionControllerSteps.the_client_issues_GET_version(VersionControllerSteps.java:30) 
at ✽.When the client calls /version(version.feature:8) 

Bu sınıf oluşturmak ettik

İşte .fe ature:

Feature: the version can be retrieved 

    As a api user 
    I want to know which api version is exposed 
    In order to be a good api user 

    Scenario: client makes call to GET /version 
    When the client calls /version 
    Then the client receives status code of 200 
    And the client receives server version 1.0 

Testlerimi salatalık ve yaylı bot kullanmak için nasıl yapılandırabilirim?

Şimdiden teşekkürler.

+0

ile döndürülen değeri işaretlemek gerekebilir? – Antonio

cevap

0

Kod listenizden ve hata günlüğünden, salatalık + yay kurulumu veya yalnızca bir uygulama hatası sorunu olup olmadığı net değil. boş gösterici durum atma hat 30

yığın izleme noktaları. Kod listenizden, result.getResponse().getContentAsString() talimatları nedeniyle göründüğü görünüyor.

Bu sizin denetleyici aslında bir vücuda dönen eğer kontrol değerinde olabilir. Örneğin siz @ResponseBody açıklama boş gösterici istisna atıyor kesin talimat

@RequestMapping(
    value = "/campaigns/new", 
    method = RequestMethod.GET, 
    ) 
    public @ResponseBody String vers() { 
     return "1.0.1"; 
    } 
İlgili konular