• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Spring Controller testing with path variable in the URL returning 404

 
Greenhorn
Posts: 14
  • 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: 2266
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.
reply
    Bookmark Topic Watch Topic
  • New Topic