Random DB or Schema for functional/unit testing on postgres? Test fixtures? #4740
Unanswered
kairoswater-jason
asked this question in
Q&A
Replies: 1 comment
-
|
The preferred way for this are test transactions. These slides (linked from the diesel homepage) have more details. That written: Diesel doesn't expose any way to create random databases for tests. The diesel test suite contains some code that does something like that. You could likely use that as basis for implementing something like that outside of diesel. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Suppose I have a postgres application that I am developing unit tests for. Unit tests need isolated from one another.
Is there any good way to change the schema of the application to some random name?
Or maybe, is it required to create a database with a random name for each unit test?
How is this sort of isolated unit testing normally done?
Source [1] talks about using test transactions on empty databases. Maybe that might be the one and only answer - although, in the back of my mind I sort of wonder if something like SQLX's Fixtures might exist for diesel testing. Sometimes it can be nice for state changes during a test to persist slightly longer than a single transaction. (for example, inside tests where there are intentional errors)
[1] #1549
Beta Was this translation helpful? Give feedback.
All reactions