-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5 #47346
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
base: main
Are you sure you want to change the base?
Conversation
- Removed JUnit 4 and junit-vintage-engine dependencies from pom.xml - Migrated 85+ test files from JUnit 4 to JUnit 5 - Updated imports from org.junit to org.junit.jupiter.api - Replaced @Before/@after with @BeforeEach/@AfterEach - Replaced @BeforeClass/@afterclass with @BeforeAll/@afterall - Replaced @RunWith with @ExtendWith for Mockito and Spring - Replaced Assert with Assertions - Removed TestRule interface from AbstractIntegrationTestCollectionManager - Fixed static imports for AssertJ and JUnit Jupiter Remaining work: - Fix a few remaining compilation errors in 3 test files - Run full test suite to ensure all tests pass Co-authored-by: Netyyyy <[email protected]>
- Successfully migrated all 85+ test files from JUnit 4 to JUnit 5 - All tests now compile successfully with JUnit 5 - Removed JUnit 4 and junit-vintage-engine dependencies - Updated all annotations and assertions - Fixed all import statements - Removed TestRule interface usage Remaining: 14 test failures to fix (mainly incorrect @test(expected=...) conversions) These tests expect exceptions but were incorrectly migrated from @test(expected=Exception.class) syntax Co-authored-by: Netyyyy <[email protected]>
- Wrapped test bodies expecting exceptions with assertThrows() in CosmosTemplateUnitTest - Wrapped test bodies expecting IllegalQueryException with assertThrows() in CriteriaUnitTest - Wrapped all test bodies expecting IllegalArgumentException with assertThrows() in SimpleCosmosRepositoryIllegalTest - Used lenient() for unused stubbing in SimpleCosmosRepositoryUnitTest to fix UnnecessaryStubbing errors All 120 tests now pass successfully. Co-authored-by: Netyyyy <[email protected]>
Fixed all pipeline test failures. The issues were from incorrect @test(expected=Exception.class) conversions that didn't properly wrap test bodies with assertThrows(). Changes in commit ec7169c:
All 120 tests now pass successfully. |
Removed junit and junit-vintage-engine dependencies.
|
/azp run java - spring - tests |
|
Azure Pipelines successfully started running 1 pipeline(s). |
JUnit 4 to JUnit 5 Migration - COMPLETE ✅
Successfully migrated all tests in azure-spring-data-cosmos from JUnit 4 to JUnit 5 in preparation for Spring Boot 4 upgrade.
Migration Checklist
Changes
Dependencies (pom.xml)
junit:junit4.13.2 dependencyjunit-vintage-enginecompatibility layerTest Annotations & Imports (85+ files)
@Before/@After→@BeforeEach/@AfterEach@BeforeClass/@AfterClass→@BeforeAll/@AfterAll@Ignore→@Disabled@RunWith(MockitoJUnitRunner.class)→@ExtendWith(MockitoExtension.class)@RunWith(SpringJUnit4ClassRunner.class)→@ExtendWith(SpringExtension.class)org.junit.Assert→org.junit.jupiter.api.AssertionsCode Refactoring
TestRuleinterface implementation fromAbstractIntegrationTestCollectionManager@ClassRuleand@Ruleannotations@Test(expected=Exception.class)toassertThrows()patternlenient()for Mockito stubbings that are not used in all testsExample Conversion
Test Results
✅ All 120 tests passing
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.