简体   繁体   中英

Karate: How do I verify a mock server is called

I'm testing a peer-to-peer app that I can send a URL to and then it should make a request to that URL. I can mock the response with the karate mock server, but I would also like to verify the request was made.

One idea I had was to log each request to the mock server to a file, then in my main scenario (which started the mock and sent the URL to the app) read it back for verification.

Is there a better way to do this? Can I access the state of the mock server from the scenario that created it without using a file. Can I tell the mock server to verify its own state?

I'm using the standalone JAR if that makes a difference.

Remember, Karate mocks are all about exposing arbitrary REST end-points that can "see" a bunch of global variables.

All you need to do is expose a "secret" end-point that your test can call to get pretty much anything you want out of the "state" of the mock.

More details here: https://stackoverflow.com/a/61374079/143475 and here: https://stackoverflow.com/a/63512034/143475

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM