Adding WireMock to your project
WireMock is distributed in two different types of JAR - a standard “thin” JAR, and a “fat” standalone JAR. The latter of these contains all of WireMock’s dependencies and repackages (shades) most of these. Either can be used as a dependency in your project and which you choose depends primarily on whether you have dependencies already present that conflict with WireMock’s. Picking the standalone version generally avoids these problems but at the cost of a larger JAR download. If you’re using Gradle you can add WireMock to your build file’s dependencies as follows. Choose one of:Configuring your test
After you’ve created a mock API in the WireMock Cloud UI, setting up a WireMock client to it is a one-line task (you can copy-paste this from your mock API’s Settings page):Programmatic stub creation
The same approach can be taken if you want to create stubs in your API programmatically. This can be useful when you require a large number of stubs and don’t want to create them all by hand. The example in the previous section creates an ephemeral stub i.e. one that isn’t stored persistently and will be deleted when the API is reset. To ensure that stubs created programmatically are saved, simply callpersistent()
during creation: