When we run test casts, we don’t want to use our development database, we want to use a new database for testing. In Xcode, it is easy to set. Under the Run
tab, we don’t set the database information, but under the Test
tab, we do.


But do you know how to set these variables via command line? Here it is:
1 | export DATABASE_PORT="5433"; export DATABASE_USERNAME="test"; export DATABASE_PASSWORD="test"; export DATABASE_NAME="test"; swift test |
If you want to cancel setting, you need to close your terminal window and open it again.
Now, CI(continutal Integration) is popular, today I also try to run test when I push my code to Github reposity. After some failture, here is the right yml
file.
1 | name: test |
I had thought to change the database port to 5433
, but it seems a bug of Github Action. After I changed it back to 5432
, it works.
Thanks to @0xTim for discussion about it.