license
Unit testing Vapor 4 applications through declarative specifications.
Add the repository as a dependency:
.package(url: "https://github.com/binarybirds/spec.git", from: "1.2.0"),
Add Spec to the target dependencies:
.product(name: "Spec", package: "spec"),
Update the packages and you are ready.
@testable import App import Spec final class BlogApiTests: XCTestCase { func testLogin(_ app: Application) throws { struct UserLoginRequest: Content { let email: String let password: String } struct UserTokenResponse: Content { let id: String let value: String } let userBody = UserLoginRequest(email: "foo@bar.com", password: "foo") var token: String? try app .describe("Login request should return ok") // describe spec .post("/api/user/login") // post to endpoint .header("accept", "application/json") // add header .body(userBody) // add content body .expect(.ok) // status code .expect(.json) // media type .expect("content-length", ["81"]) // expect header .expect(UserTokenResponse.self) { content in // expect content token = content.value // retrieve content } .test(.inMemory) // test in memory _ = try XCTUnwrap(token) } }
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
Spec
Unit testing Vapor 4 applications through declarative specifications.
Install
Add the repository as a dependency:
Add Spec to the target dependencies:
Update the packages and you are ready.
Usage example
Api