Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TransactionFactory, Transaction test cases #3277

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mawen12
Copy link
Contributor

@mawen12 mawen12 commented Oct 17, 2024

Supplement the missing unit test cases for TransactionFactory, Transaction.

@coveralls
Copy link

coveralls commented Oct 17, 2024

Coverage Status

coverage: 87.301% (+0.1%) from 87.18%
when pulling 067b46a on mawen12:feature-transaction-test
into 2a5fad6 on mybatis:master.

Copy link
Member

@hazendaz hazendaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the base class so test is not in its name as that is the trigger to look for tests with Surefire. Probably just change that to 'base' so it's clear it's purple is for real tests to implement. Thanks.

@mawen12
Copy link
Contributor Author

mawen12 commented Oct 18, 2024

Hi, thanks your advice, I have rename base test class.

  • TransactionTest -> BaseTransactionTest
  • TransactionFactoryTest -> BaseTransactionFactoryTest

@hazendaz
Copy link
Member

I think you may have misunderstood me. The class 'BaseTransactionTest', I don't want to see 'Test' in the class name. That is what surefire uses to tell it to scan for tests. There are no tests in that class. Its an interface you are using for your other tests to inherit. Thus it is a base class, so what I meant was try something like 'TransactionBase' instead of 'TransactionTest'. Same with the other base class. Does that make sense? Basic reason is that there is no reason for surefire to scan those 2 interfaces / abstract classes as nothing in there to process. Its the real tests that are tested plus naming this way makes it clear. Otherwise I'd think there were tests in there.

@mawen12
Copy link
Contributor Author

mawen12 commented Oct 18, 2024

Sorry, i will change the class name as you expcted.
I just have found my other commits exists same problems. Like SqlNodeTest and ObjectWrapperBaseTest.


@Test
@Override
public void shouldCommit() throws SQLException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of using inheritance here, the reader of this test would require extensive knowledge of internals. In other words, shouldCommit in this case verifies that commit is never called, which can be quite confusing, and might even be seen as an incorrect test case. So not sure if using the inheritance here is a great idea.

Either it should be renamed, or a class level comment explaining this should be added imo.

Copy link
Contributor Author

@mawen12 mawen12 Oct 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I have found the problem, because ManagedTransaction do not manage connection's rollback and commit, so it will never call commit and rollback method in Connection class.


transactionFactory.setProperties(properties);

assertTrue((Boolean) getValue(transactionFactory.getClass().getDeclaredField("skipSetAutoCommitOnClose"), transactionFactory));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, using constructs like assertTrue, or assertEquals(true, xxx) does not make it that clear what went wrong initially in test output.

It's more a personal thing, but I prefer using assertj, as the failure messages are more descriptive. Not sure what others think.

@mawen12
Copy link
Contributor Author

mawen12 commented Oct 24, 2024

@hazendaz Hi, I have changed the test class name. If you find more issues, i will fix it. Thanks.

@hazendaz
Copy link
Member

Will be a few days but will get to this.

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.

4 participants