How does DBT TEST CASES work

Hi All,
i am working on the dbt test cases. but wondering if dbt test on the existing table or on the table that going to be generated. for example, if i have a table a in the database, i will use dbt run command to refresh it. before refresh the table, i want to have test cases to test on the data. so if i run the dbt test, will dbt do the test on the existing tables in the database or dbt will prepopulate the table using dbt model files, and then do the test on that prepopulated table rather than test on the existing database table?
example:
table a in the database, it has duplicated data. but if i run the dbt run to refresh this table a, the duplicated data will be gone because today’s data in the source is not duplicated any more. question: if unique test case gonna failed if i run dbt test before dbt run? will dbt test going to test on unrefreshed table or refreshed table

You are correct, tests run on tables and views after they are created in the target schema.

You should develop into your own development schema, and only merge changes and build relations in your prod schema after your code has been thoroughly tested.

For an additional layer of QA, you should look into blue/green deployments, which will let you hold back changes from prod until after all of the newly built relations have been tested.

Performing a blue/green deploy of your dbt project on Snowflake

thanks so much for the info. This is exactly what i am looking for, thanks
Alex