Testing with spring-test-mvc jsonpath returns null

后端 未结 2 917
不知归路
不知归路 2021-01-06 18:43

I am using Spring\'s \"spring-test-mvc\" library to test web controllers. I have a very simple controller that returns a JSON array. Then in my test I have:

         


        
2条回答
  •  时光说笑
    2021-01-06 19:23

    If you add the json path dependency to maven, or add the jar to your lib, then it will work. I think that Spring is not including the jsonPath dependency in the latest Spring 3.2.0 RC1 release. I'm guessing that this is the same for Spring-Test-MVC standalone project as well.

    Here is the dependency for Maven:

    
        com.jayway.jsonpath
        json-path
        0.8.1
        test
    
    

    You might also need the hamcrest library to use the jsonPath("$.test").value("test")

    
        org.hamcrest
        hamcrest-library
        1.3
        test
    
    

提交回复
热议问题