This is by far the easiest way to get setup. First, create a directory:
mkdir MyPackage
cd MyPackage
Now, use SPM to init your package:
swift package init --type library
All of your files will be generated automatically and you're now ready to setup Travis and Codecov
Package.swift file in the root
import PackageDescription
let package = Package(
name: "MyPackage",
dependencies: [
// Add dependencies
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 1),
]
)
Create and put your sources in the directory
Sources/MyPackage/
Create and put your tests in the directory
Tests/MyPackageTests/
In order to support Linux, add Tests/LinuxMain.swift
the following file with all of your XCTestCase
s.
import XCTest
@testable import MyPackageTests
XCTMain([
testCase(MyPackageTests.allTests)
])
import XCTest
@testable import NeededImport
class MyPackageTests: XCTestCase {
static var allTests = [
("test", test)
]
func test() {
XCTAssertEqual("abc", "abc")
}
}
For Travis
add the following file to your project root:
os:
- linux
- osx
language: generic
sudo: required
dist: trusty
osx_image: xcode8
script:
- eval "$(curl -sL https://swift.vapor.sh/ci)"
- eval "$(curl -sL https://swift.vapor.sh/codecov)"
For Codecov
add the following file to your project root:
coverage:
ignore:
- "Whatever folder"
Generate an Xcode project:
vapor xcode -y
The hotkey to build and run unit tests is cmd+u
.