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

Merged
merged 7 commits into from
Dec 28, 2024

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.292% (+0.1%) from 87.171%
when pulling dcca250 on mawen12:feature-transaction-test
into 266542a 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.

Copy link
Member

Choose a reason for hiding this comment

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

I'm ok with how this is for now. Yes assertj makes it a lot more readable. Possibly we can run open rewrite against this for tests to clean them up. Will check into that separately.

@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.

@hazendaz
Copy link
Member

merge conflicts need to be resolved before this can progress.

# Conflicts:
#	src/test/java/org/apache/ibatis/scripting/xmltags/ChooseSqlNodeTest.java
#	src/test/java/org/apache/ibatis/scripting/xmltags/ForEachSqlNodeTest.java
#	src/test/java/org/apache/ibatis/scripting/xmltags/MixedSqlNodeTest.java
@mawen12
Copy link
Contributor Author

mawen12 commented Dec 28, 2024

merge conflicts need to be resolved before this can progress.

Hi, I have resolved merge conflicts.

@hazendaz
Copy link
Member

@mawen12 coverage provided by this is likely none. While it shows +0.1% that is within normal bounds for it changing just depending on the build. Going to merge it otherwise. There are some formatting issues so those will get applied after. Next time around, do make sure to run mvn clean install before submitting to ensure all the plugins run.

@hazendaz hazendaz merged commit a943a1b into mybatis:master Dec 28, 2024
19 checks passed
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