That all looks valid. If you do swift test from the command line, what error do you get? Also what does your configure.swift look like for setting up the DB? Looks like a DB connection issue
$ swift test
[3/3] Linking TILAppPackageTests
Test Suite 'All tests' started at 2019-09-25 22:00:23.885
Test Suite 'TILAppPackageTests.xctest' started at 2019-09-25 22:00:23.885
Test Suite 'AppTests' started at 2019-09-25 22:00:23.885
Test Case '-[AppTests.AppTests testNothing]' started.
Test Case '-[AppTests.AppTests testNothing]' passed (0.081 seconds).
Test Suite 'AppTests' passed at 2019-09-25 22:00:23.966.
Executed 1 test, with 0 failures (0 unexpected) in 0.081 (0.081) seconds
Test Suite 'UserTests' started at 2019-09-25 22:00:23.966
Test Case '-[AppTests.UserTests testUsersCanBeRetrievedFromAPI]' started.
[ INFO ] Migrating 'psql' database (/Users/arco/Projects/vapor/TILApp/.build/checkouts/fluent/Sources/Fluent/Migration/MigrationConfig.swift:69)
[ INFO ] Migrations complete (/Users/arco/Projects/vapor/TILApp/.build/checkouts/fluent/Sources/Fluent/Migration/MigrationConfig.swift:73)
Test Case '-[AppTests.UserTests testUsersCanBeRetrievedFromAPI]' passed (0.126 seconds).
Test Suite 'UserTests' passed at 2019-09-25 22:00:24.092.
Executed 1 test, with 0 failures (0 unexpected) in 0.126 (0.126) seconds
Test Suite 'TILAppPackageTests.xctest' passed at 2019-09-25 22:00:24.092.
Executed 2 tests, with 0 failures (0 unexpected) in 0.206 (0.207) seconds
Test Suite 'All tests' passed at 2019-09-25 22:00:24.092.
Executed 2 tests, with 0 failures (0 unexpected) in 0.206 (0.207) seconds
And my configure.swift:
import FluentPostgreSQL
import Vapor
/// Called before your application initializes.
public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
// Register providers first
try services.register(FluentPostgreSQLProvider())
// Register routes to the router
let router = EngineRouter.default()
try routes(router)
services.register(router, as: Router.self)
// Register middleware
var middlewares = MiddlewareConfig() // Create _empty_ middleware config
// middlewares.use(FileMiddleware.self) // Serves files from `Public/` directory
middlewares.use(ErrorMiddleware.self) // Catches errors and converts to HTTP response
services.register(middlewares)
var databases = DatabasesConfig()
let databaseName: String
let databasePort: Int
if env == .testing {
databaseName = "vapor-test"
databasePort = 5433
} else {
databaseName = "vapor"
databasePort = 5432
}
let databaseConfig = PostgreSQLDatabaseConfig(
hostname: "localhost",
port: databasePort,
username: "vapor",
database: databaseName,
password: "password"
)
let database = PostgreSQLDatabase(config: databaseConfig)
databases.add(database: database, as: .psql)
services.register(databases)
// Configure migrations
var migrations = MigrationConfig()
migrations.add(model: User.self, database: .psql)
migrations.add(model: Acronym.self, database: .psql)
migrations.add(model: Category.self, database: .psql)
migrations.add(model: AcronymCategoryPivot.self, database: .psql)
services.register(migrations)
}