尝试运行JUnit测试时获取groovy.lang.MissingPropertyException

时间:2019-03-14 12:50:42

标签: java spring-mvc groovy junit spock

这是我正在运行的测试,但是在执行代码时失败了,并给了我一个缺少的属性异常。

package travelTests

import org.springframework.beans.factory.annotation.Autowired

import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.ResultActions
import org.springframework.web.context.WebApplicationContext
import static     org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get

import spock.lang.Shared
import spock.lang.Specification
import travel.TravelApp
import travel.controller.PlaceController
import travel.repository.RoleRepository
import travel.repository.StatusRepository
import travel.repository.UserRepository


@SpringBootTest(classes=[TravelApp.class,PlaceController.class])
class TransTest extends Specification{
@Autowired
UserRepository userRepo;

@Autowired
RoleRepository roleRepo;

@Autowired
StatusRepository todoRepo;

@Autowired
private WebApplicationContext wac;

private MockMvc mockMvc;
private ResultActions result;

@Shared
private boolean first = true;
@Shared
private int id = -1;


def "chooseaplace"() {
    given: "the controller is setup"
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build()
    when: "when choosing a location on  /addcountry/"
        result = this.mockMvc.perform(get("/Country/"))
    then: "I should see the view 'form/Country'"
        result.andExpect(view().name('form/Country'))}
}

运行此代码时,它将显示异常。我在哪里出错,groovy.lang.MissingPropertyException no such property: MockMvcBuilders for class:travelTests.TransTest是什么?

谢谢

0 个答案:

没有答案