Chapter 11 Testing

When trying to test on linux using docker compose, when I run
docker-compose up --abort-on-container-exit
when compiling Swift Module ‘TILAppPackageTests’ (1 sources)
I get multiple errors complaining about ‘AcronymTests’, ‘CategoryTests’ and ‘UserTests’ being unresolved identifiers. Any ideas?

@0xtim Can you please help with this when you get a chance? Thank you - much appreciated! :]

@bababoega dod you have @testable import App in your LinuxMain.swift

Otherwise can you post the full build output?

Ah I’ll try that later today! I just had
@testable import AppTests

(As per the book)
Thanks for helping out. So I should add
@testable import App
In addition to what was already there?

Ah sorry I meant AppTests

ah ok in that case here’s the full build output:
docker-compose up --abort-on-container-exit
returns:

Starting tilapp_postgres_1 ... done
Recreating tilapp_til-app_1 ... done
Attaching to tilapp_postgres_1, tilapp_til-app_1
postgres_1  | 2018-11-19 23:16:57.455 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
postgres_1  | 2018-11-19 23:16:57.455 UTC [1] LOG:  listening on IPv6 address "::", port 5432
postgres_1  | 2018-11-19 23:16:57.458 UTC [1] LOG:  listening on Unix socket        "/var/run/postgresql/.s.PGSQL.5432"
postgres_1  | 2018-11-19 23:16:57.472 UTC [25] LOG:  database system was shut down at 2018-11-19 23:12:04 UTC
postgres_1  | 2018-11-19 23:16:57.477 UTC [1] LOG:  database system is ready to accept connections
til-app_1   | Compile libbcrypt blf.c
til-app_1   | Compile CNIOZlib empty.c
til-app_1   | Compile CNIOSHA1 c_nio_sha1.c
til-app_1   | Compile libbcrypt bcrypt.c
til-app_1   | Compile Swift Module 'NIOPriorityQueue' (2 sources)
til-app_1   | Compile Swift Module 'Debugging' (3 sources)
til-app_1   | Compile Swift Module 'COperatingSystem' (1 sources)
til-app_1   | Compile CNIOOpenSSL empty.c
til-app_1   | Compile CNIOLinux shim.c
til-app_1   | Compile CNIOHTTPParser c_nio_http_parser.c
til-app_1   | Compile CNIODarwin shim.c
til-app_1   | Compile CNIOAtomics src/c-atomics.c
til-app_1   | Compile Swift Module 'NIOConcurrencyHelpers' (2 sources)
til-app_1   | Compile Swift Module 'NIO' (52 sources)
til-app_1   | Compile Swift Module 'NIOTLS' (3 sources)
til-app_1   | Compile Swift Module 'NIOFoundationCompat' (1 sources)
til-app_1   | Compile Swift Module 'Bits' (12 sources)
til-app_1   | Compile Swift Module 'NIOHTTP1' (8 sources)
til-app_1   | Compile Swift Module 'Async' (15 sources)
til-app_1   | Compile Swift Module 'NIOOpenSSL' (13 sources)
til-app_1   | Compile Swift Module 'Random' (4 sources)
til-app_1   | Compile Swift Module 'Core' (25 sources)
til-app_1   | Compile Swift Module 'NIOWebSocket' (8 sources)
til-app_1   | Compile Swift Module 'URLEncodedForm' (8 sources)
til-app_1   | Compile Swift Module 'Service' (20 sources)
til-app_1   | Compile Swift Module 'Validation' (16 sources)
til-app_1   | Compile Swift Module 'Multipart' (8 sources)
til-app_1   | Compile Swift Module 'Logging' (4 sources)
til-app_1   | Compile Swift Module 'HTTP' (23 sources)
til-app_1   | Compile Swift Module 'TemplateKit' (41 sources)
til-app_1   | Compile Swift Module 'Routing' (12 sources)
til-app_1   | Compile Swift Module 'DatabaseKit' (30 sources)
til-app_1   | Compile Swift Module 'Crypto' (13 sources)
til-app_1   | Compile Swift Module 'Console' (27 sources)
til-app_1   | Compile Swift Module 'SQL' (58 sources)
til-app_1   | Compile Swift Module 'WebSocket' (5 sources)
til-app_1   | Compile Swift Module 'Command' (16 sources)
til-app_1   | Compile Swift Module 'Fluent' (49 sources)
til-app_1   | Compile Swift Module 'Vapor' (75 sources)
til-app_1   | Compile Swift Module 'PostgreSQL' (72 sources)
til-app_1   | Compile Swift Module 'FluentSQL' (9 sources)
til-app_1   | Compile Swift Module 'FluentPostgreSQL' (17 sources)
til-app_1   | Compile Swift Module 'App' (10 sources)
til-app_1   | Compile Swift Module 'Run' (1 sources)
til-app_1   | Compile Swift Module 'AppTests' (3 sources)
til-app_1   | Linking ./.build/x86_64-unknown-linux/debug/Run
til-app_1   | Compile Swift Module 'TILAppPackageTests' (1 sources)
til-app_1   | /package/Tests/LinuxMain.swift:7:12: error: use of unresolved identifier 'AcronymTests'
til-app_1   |   testCase(AcronymTests.allTests),
til-app_1   |            ^~~~~~~~~~~~
til-app_1   | /package/Tests/LinuxMain.swift:8:12: error: use of unresolved identifier 'CategoryTests'
til-app_1   |   testCase(CategoryTests.allTests),
til-app_1   |            ^~~~~~~~~~~~~
til-app_1   | /package/Tests/LinuxMain.swift:9:12: error: use of unresolved identifier 'UserTests'
til-app_1   |   testCase(UserTests.allTests)
til-app_1   |            ^~~~~~~~~
til-app_1   | error: terminated(1): /usr/bin/swift-build-tool -f /package/.build/debug.yaml test output:
til-app_1   |     
til-app_1   | 
tilapp_til-app_1 exited with code 1
Aborting on container exit...
Stopping tilapp_postgres_1  ... done

Also docker-compose build returns

postgres uses an image, skipping

Building til-app

Step 1/6 : FROM swift:4.2

---> 2f707d99706c

Step 2/6 : WORKDIR /package

---> Using cache

---> faaf6b1d7f00

Step 3/6 : COPY . ./

---> e52e01a8b0ee

Step 4/6 : RUN swift package resolve

---> Running in 9a0a22048bd5

Removing intermediate container 9a0a22048bd5

---> f2f93701e9e3

Step 5/6 : RUN swift package clean

---> Running in 30ae3bb1920b

Removing intermediate container 30ae3bb1920b

---> c973d4c8109c

Step 6/6 : CMD ["swift", "test"]

---> Running in 88ef335c6363

Removing intermediate container 88ef335c6363

---> c40d98e179da

Successfully built c40d98e179da

Successfully tagged tilapp_til-app:latest

very strange, I took a another look and all of a sudden my LinuxMain file was totally empty? Anyway I reimplemented everything according to the book and now the tests are successful. Not quite sure what went wrong

Well that is weird! Glad it’s working now though!

I just want to chime in and say I experienced the exact same issue.

My LinuxMain.swift file was also strongly emptied after a reboot.

Steps to fix it:

  • Restored the contents of Tests/LinuxMain.swift
  • Deleted Dockerfile.web (I did not add the .web extension)
  • Restored the contents of Dockerfile and docker-compose.yml.
  • Again ran:
    docker-compose build
  • and lastly:
    docker-compose up --abort-on-container-exit