TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jul 2016 |
SPMSupports SPM | ✗ |
Maintained by Pedro Piñera.
To run the example project, clone the repo, and run pod install
from the Example directory first.
Szimpla is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "Szimpla"
Szimpla saves the snapshots in a folder that you specify using an environment variable, SZ_REFERENCE_DIR
. Open your project scheme, and in the Run section, add the variable to the Environment Variables section. The value should be the folder where you would like your network snapshots to be saved.
Name | Value |
---|---|
SZ_REFERENCE_DIR | $(SOURCE_ROOT)/$(PROJECT_NAME)Tests/Szimpla |
In order to record the sent requests it’s very important to start the server when your app is built for UI tests:
Add the tearUp()
method to the AppDelegate as shown below:
import Szimpla
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if isUIBuild {
try! Szimpla.Server.instance.tearUp()
}
return true
}
And in your requests make sure you use the configuration provided by the Szimpla server:
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
if isUIBuild {
configuration = Szimpla.Server.instance.sessionConfiguration(fromConfiguration: configuration)
}
The first step when testing Network requests is recording the requests in a .json
file. This file will be used for validating future tests executions. Using Szimpla to get these requests saved is very simple:
import Szimpla
// Navigate to the point where you would like to start testing.
try! Szimpla.Client.instance.start() // Starts recording
// Do all your UI tests steps
try! Szimpla.Client.instance.record(path: "share/player.json") // Saves the recorded requests
Requests will be saved under ${SZ_REFERENCE_DIR}/share/player.json
Szimpla validates:
Since most of the time values might be relative, Szimpla support using regular expressions for your .json
fields. Once you have your .json
file with the requests recorded:
The validation process is similar to the recording one. The only difference in this case is the method used to complete:
import Szimpla
// Navigate to the point where you would like to start testing.
try! Szimpla.Client.instance.start() // Starts recording
// Do all your UI tests steps
Szimpla.Client.instance.validate(path: "share/player.json") // Validates the recorded requests
It the validation fails, it’ll assert using XCTAssert
printing the validation error.
Since you might not be interested in all the requests you can decide which ones using filters. Filters conform the protocol RequestFilter
and it’s public, thus, you can create your own filters. When requests are recorded or matched you can provide a filter to be used instead of recording all the requests.
Szimpla also provides some default filters that you can use:
Pedro Piñera Buendía, [email protected]
Szimpla is available under the MIT license. See the LICENSE file for more info.