VaporTestUtils

Swift Vapor Swift Package Manager License

安装

VaporTestUtils 可通过 Swift Package Manager 获取。要安装,只需将以下行添加到您的 Package.swift 文件中的 dependencies 中。

let package = Package(
    name: "YourProject",
    dependencies: [
        ...
        .package(url: "https://github.com/Appsaurus/VaporTestUtils", from: "1.0.0"),
    ],
    targets: [
      .testTarget(name: "YourApp", dependencies: ["VaporTestUtils", ... ])
    ]
)
        

用法

查看此项目中包含的应用程序以获取完整示例。以下是一些基本知识

1. 导入库

import XCTVaporExtensions

2. 设置您的测试用例

创建一个继承自 VaporTestCase 的测试用例。覆盖计算属性 booterconfigurer 并从您的应用程序返回相应的 bootconfigure 函数。然后,只需开始执行请求。非常简单。

final class ExampleAppTests: VaporTestCase {

	static var allTests = [
		("testLinuxTestSuiteIncludesAllTests", testLinuxTestSuiteIncludesAllTests),
		("testMyApp", testMyApp)
	]

	func testLinuxTestSuiteIncludesAllTests(){
		assertLinuxTestCoverage(tests: type(of: self).allTests)
	}

	override var booter: AppBooter{
		return ExampleApp.boot
	}
	
	override var configurer: AppConfigurer{
		return ExampleApp.configure
	}
	
	override func setUp() {
		super.setUp()
		loggingLevel = .debug //This is optional. Logs all requests and responses to the console.
	}

	func testMyApp() throws {
		let response = try executeRequest(method: .GET, path: "testing-vapor-apps")
		XCTAssert(response.has(statusCode: .ok))
		XCTAssert(response.has(content: "is super easy"))
	}
}

致谢

一些扩展方法明显借鉴自 LiveUI 的 VaporTestTools。您也应该查看他们的库,因为它服务于类似的目的(甚至可能更好)。

贡献

我们非常欢迎您为 VaporTestUtils 做出贡献,请查看 CONTRIBUTING 文件以获取更多信息。

许可证

VaporTestUtils 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。