Skip to content

Conversation

@Wang-Benjamin
Copy link

Problem

When the execution order of tests are shuffled, if tests (polluters) that make modifications on the database run before tests (victims) that rely on the original/unmodified database, the database will be polluted and victim tests will fail with assertionError.

Involved tests:

tk.mybatis.mapper.test.country.TestExistsWithPrimaryKey.testDynamicExistsWithPrimaryKey
tk.mybatis.mapper.test.country.TestInsert.testDynamicInsert
tk.mybatis.mapper.test.example.TestSelectByExample.testAndExample
tk.mybatis.mapper.test.example.TestSelectByExample.testAndOr
tk.mybatis.mapper.test.example.TestSelectByExample.testExcludeColumnsByExample
tk.mybatis.mapper.test.example.TestSelectByExample.testOrderBy
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExample
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExample2
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExample3
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExample4
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExampleForUpdate
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExampleInNotIn
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectByExampleInNotIn2
tk.mybatis.mapper.test.example.TestSelectByExample.testSelectPropertisCheckCorrect

The above are all order-dependent victim tests and they test the properties of database without modification.

Take TestExistsWithPrimaryKey.testDynamicExistsWithPrimaryKey as an example:

Country country = new Country();
country.setId(35);
Assert.assertEquals(true, mapper.existsWithPrimaryKey(country));

country.setId(0);
Assert.assertEquals(false, mapper.existsWithPrimaryKey(country));

It expects country with id=35 exists in the database but it actually fails with assertionError if polluter tests that delete/modify the country with id=35 in the database run before it.

Proposed Fix

A simple and safe way to ensure victim tests can work as we expect is to reset/clean the database before executing such tests.

Glad to discuss this issue if you have concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant