My tests were failing because of a class not found exception on
import com.jayway.jsonpath.InvalidPathException;
within
org.springframework.test.util.JsonPathExpectationsHelper;
Manually adding the jayway dependency to my maven pom removed this error and my test ran as expected.
Have I found a bug, or do I need to add a different spring jar as well as spring test ?
In my case
Having test code what contained jsonPath usage:
mockMvc.perform(get("/api/userDetails").header("Authorization", base64ForTestUser).accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("userName").value("testUser"));
I was getting
java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException
and
java.lang.ClassNotFoundException: com.jayway.jsonpath.InvalidPathException
This error was directly caused by lack of such dependencies
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
External dependencies (e.g., JUnit, Mockito, Easy Mock, JayWay, etc.) are not included in Spring, so it is necessary to explicitly add them (Ant/Maven/Ivy dependency, or jar files) to the project's classpath.
Adding this dependency worked
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
If you want to use another version of json-path-assert you can review the following repository:
http://mvnrepository.com/artifact/com.jayway.jsonpath/json-path
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With