• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Spring Controller testing with path variable in the URL returning 404

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,  

I am trying to write a unit test for my Spring controller using MockMvc. The issue is that if I have path variable in the URL I end up getting a 404.

Here is my controller code:  




I've tried use param, content type JSON and also specifying the string in the path directly. What's going wrong? Please suggest. I am unable to test any end point containing path variables, the ones request params and request bodies go fine. I'm using SpringBoot 2.1.3.RELEASE and Java 8.


This is what I see in the console:

 
Bartender
Posts: 2037
13
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Ron,
I am not sure what happen and I am not familiar with Junit 4's RunWith.
But one thing you can try is to add @AutoConfigureMvc to ingest the MockMvc.
I guess your MockMvc is null in your code.
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic