-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This wiki contains all the details of setting up and using Voodoo.
Voodoo is designed to act as a mock server for testing and developing applications. Essentially it's designed to simulate the API provided by a real server without all the overhead of complicated processing, databases and none API tasks.
This makes Voodoo very fast when starting and responding to requests. Important aspects when being used in testing situations.
Essentially there are a number of purposes Voodoo can be put to:
- As an embedded server within XCTests.
- As a standalone command line server.
- As an embedded server within an app. For example, to build in a "demo" mode.
In other words Voodoo is quite flexible as to how you can use it.
Voodoo was designed for two main scenarios, XCTest and Android testing. XCTests can use Voodoo via an API, where as Android can make use of a standalone server. the standalone server mode can also be a choice when you want to share the setup between Android and iOS.
A typical scenario in Xcode is to use the Voodoo API when developing UI Tests. The first thing to do in your test is to import Voodoo:
import Voodoo
Then start and configure the server with the endpoints you need:
class MyTests: XCTestCase {
private var server: VoodooServer!
private var app: XCUIApplication!
func setUp() {
server = VoodooServer(templatePath: resourcesURL.appendingPathComponent("templates/scenario1")) {
// Common endpoints.
Endpoint(.GET, "/config", response: .json(["featureFlag": true]))
Endpoint(.POST, "/login", response: .ok())
}
app = XCUIApplication()
// Make sure we pass the server URL to the app. This is assuming you have coded
// your app to look for a server being passed via a launch argument.
app.launchArguments = ["--server", server.url.absoluteString]
app.launch()
}
func testSomething() {
// Test specific response
Endpoint(.GET, "/items", response: .template("itemsList"))
// ... now test
}
}
As you can see, endpoint configurations can be set when starting the server as well as later depending on your needs.
Standalone mode is useful for testing Android apps and makes use of YAML and Javascript to define the configuration. YAML for the configuration, Javascript for dynamic responses. The setup is quite flexible. It can be loaded from a directory of YAML documents, an single YAML document that includes other YAML documents or any combination there of.
For example here is a single file with multiple endpoints.
- http
api get /config
response:
status: 200
body:
json:
featureFlag: true
- http
api post /login
response:
status: 200
Which we can use when launching Voodoo from a shell:
$ voodoo --config scenario1.yml