Hands-On Server-Side Web Development with Swift
上QQ阅读APP看书,第一时间看更新

Preparing a test executable target

In general, you want to create two executable targets for your project: one for the main application and another for the test application. Since Swift builds and runs one application at a time, you have to make your code testable by splitting the code into an application and library. The library will contain most of your business logic. The test executable file is separated from the main executable file. Both executable targets will be dependent on the core library you've just created.

In Package.swift of your Vapor 3 boilerplate project, you can see a test executable target defined:

 .testTarget(name: "AppTests", dependencies: ["App"])

This test target is named AppTests and it is dependent on a library called App.

You can add more test targets to a project by inserting a new test target into Package.swift. You simply choose one of the targets to run the tests contained in the target.