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

test: migrate client module api tests to junit 5 #4377

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

Conversation

sherlock-lin
Copy link
Contributor

Descriptions of the changes in this PR:

Fix #4322

Main Issue: #4322

@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch 2 times, most recently from bcc59bb to da302e5 Compare May 21, 2024 08:24
@sherlock-lin sherlock-lin reopened this May 21, 2024
@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch from da302e5 to e85971e Compare May 21, 2024 09:38
@sherlock-lin
Copy link
Contributor Author

@shoothzj

@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch 6 times, most recently from 407fc29 to f0aa9af Compare May 22, 2024 01:55
@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch from f0aa9af to 859af11 Compare May 22, 2024 07:29
/**
* Unit Test Context Information.
*/
public class TestContextExtension implements BeforeEachCallback {
Copy link
Member

Choose a reason for hiding this comment

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

I think we can put this common class into testtools, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can put this common class into testtools, WDYT?

Of course, I would also like this class to become more generalized, how do I add it to testtools please?

Copy link
Member

Choose a reason for hiding this comment

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

This class isn't needed. Junit5 already contains TestInfo for this purpose.
Please check https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection for the example.

Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

Use JUnit5's TestInfo instead of adding custom extension.

@shoothzj
Copy link
Member

@lhotari Thanks for you remind, I remember this class too, and it has been used in

void setTestNameJunit5(TestInfo testInfo) {
testName = testInfo.getDisplayName();
}

public static Collection<Object[]> data() {
return Arrays.asList(new Object[][]{
{true},
{false}
});
}

@Test
public void testOpenLedger() throws Exception {
@MethodSource("data")
Copy link
Member

@lhotari lhotari May 29, 2024

Choose a reason for hiding this comment

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

In junit5, it's better to use @ValueSource(booleans = {true, false}) for cases where there's a single boolean parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lhotari Thanks,It's a better choice.

@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch 2 times, most recently from 8cb695d to 2615c36 Compare May 31, 2024 01:36
Copy link
Member

@shoothzj shoothzj left a comment

Choose a reason for hiding this comment

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

minor nits: I think volatile in private volatile String testName; might be useless

@sherlock-lin sherlock-lin force-pushed the sherlock-migrate-to-junit5-0516 branch from 2615c36 to 84335b9 Compare June 6, 2024 02:09
@sherlock-lin
Copy link
Contributor Author

minor nits: I think volatile in private volatile String testName; might be useless

done :)

@@ -264,6 +267,7 @@ private DigestManager getDigestType(long ledgerId) throws GeneralSecurityExcepti
UnpooledByteBufAllocator.DEFAULT, false);
}

@AfterEach
@After

Choose a reason for hiding this comment

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

how about add some todo here: // TODO: delete @Before when only run with junit5

@@ -141,6 +143,7 @@ public MockEntry(byte[] payload, long lastAddConfirmed) {

}

@BeforeEach
@Before

Choose a reason for hiding this comment

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

how about add some todo here: // TODO: delete @Before when only run with junit5

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.

Migrate tests from junit4 to junit5
4 participants