Chapter 11 Error running tests - Application+testable not working

func testUsersCanBeRetrievedFromAPI()  throws {
      let user = try User.create(
        name: usersName,
        username: usersUsername,
        on: app.db) ----> Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
      _ = try User.create(on: app.db)

if this code is repeated for every function

        let app = Application(.testing)
     
        defer { app.shutdown() }
      
        try await configure(app)
          
        try await app.autoRevert().get()
        try await app.autoMigrate().get()

then all tests work but not if it is in application+testable

This code should live in the setUp function of the test case

1 Like

OK, Thank you for all the help

Sorry, I can’t solve it.

What’s the error you get?

Hi Tim
Do you mean the application extension code should be in the setUpWithError() function override? In the book it’s in a separate file called Application+Testable.swift. I’m getting the same error that Sandhums initially posted.

Yep see how it’s done here https://github.com/kodecocodes/vapor-til/blob/main/Tests/AppTests/AcronymTests.swift#L39-L43

There are newer async and throwing set ups you can use now but it’s the same effect