Is there is any way to emulate database in Db Connections in UnitTests?
Part of the functionality of my plugin uses database structure obtained from a database connection.
To do Unit tests I create a fake database using code.
But in last versions of Database plugin DataSources became immutable, so my code fails to add a database to database connections.Code that stopped working:
```
DbPsiFacade facade = DbPsiFacade.getInstance(myFixture.getProject());
TestDataSource source = new TestDataSource(myFixture.getProject());
List<DbDataSource> dataSources = facade.getDataSources().add(source); <- OperationNotSupported
```
How can I create fake database in unit tests so it would be availible as it would be in Database Connections?
请先登录再写评论。
Oleg,
DbPsiFacade and DbDataSource are probably too high-level for a unit test.
Please provide a sample test source so we can figure out the right API for that.
Thanks for reply.
it is actually Functional tests if we follow terminology. In the documentation JetBrains says that most effective way is to use functional tests mostly, and I also like this approach.
Example test:
(This method is located in com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase descendant.)
PersonModel is an ActiveRecord, plugin figure out database table and shows column names in <caret>.
Plugin finds table columns by traversing dataSources like that
I use following SetUp code:
This line stopped working. I would like to find a "good" way to emulate database, so plugin gets fake database structure, and we can effectively test our plugin code.
Thanks.
For reference, one of affected files:
https://github.com/nvlad/yii2support/blob/master/tests/com/nvlad/yii2support/database/QueryTests.java
Please see https://youtrack.jetbrains.com/issue/IJSDK-328
Thanks a lot!