Migrate all TestNG tests to JUnit 5#10
Open
devin-ai-integration[bot] wants to merge 3 commits intodevelop-7.0.xfrom
Open
Migrate all TestNG tests to JUnit 5#10devin-ai-integration[bot] wants to merge 3 commits intodevelop-7.0.xfrom
devin-ai-integration[bot] wants to merge 3 commits intodevelop-7.0.xfrom
Conversation
- Replace TestNG annotations with JUnit 5 equivalents (@test, @BeforeAll, @afterall, @beforeeach, @AfterEach) - Convert 5 base test classes to use @ExtendWith(SpringExtension.class) and @testinstance(PER_CLASS) - Convert @DataProvider/@test(dataProvider) patterns to @ParameterizedTest/@MethodSource - Replace TestNG Assert with JUnit 5 Assertions - Remove TestNG dependency from integration/pom.xml - Add JUnit Jupiter 5.10.2 dependencies - Remove surefire-testng from maven-surefire-plugin - Stop excluding junit-jupiter from spring-boot-starter-test - Fix logger reference in MVELTest (was from AbstractTestNGSpringContextTests) - All 60 files migrated, zero TestNG imports remain - Verified: mvn test-compile -pl integration passes Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
…s args, add @TestMethodOrder/@order - Issue #1: Remove unused Method parameter from CustomerPhoneControllerTest.setupCustomerId() to prevent JUnit 5 ParameterResolutionException - Issue #2: Swap assertEquals argument order from TestNG convention (actual, expected) to JUnit 5 convention (expected, actual) in RollbackTest, SystemPropertiesTest, WorkflowTest - Issue #3: Add @TestMethodOrder(MethodOrderer.OrderAnnotation.class) and @order(N) annotations to 21 test classes with execution order dependencies to preserve test method ordering - Use fully qualified @org.junit.jupiter.api.Order where it conflicts with domain Order class Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Migrates all TestNG-based tests to JUnit 5 (Jupiter) across the integration module. TestNG is fully removed as a dependency. This is a pure test framework migration — no test logic was changed.
Labels: Enhancement, Status: ready-for-code-review
Changes
POM (
integration/pom.xml)org.testng:testng:7.8.0dependencysurefire-testngprovider frommaven-surefire-plugin(keptsurefire-junit-platform)junit-jupiter:5.10.2andjunit-jupiter-params:5.10.2junit-jupiter-apiandjunit-jupiter-enginefromspring-boot-starter-testBase test classes (5 classes)
TestNGSiteIntegrationSetup,TestNGAdminIntegrationSetup: replacedextends AbstractTestNGSpringContextTestswith@ExtendWith(SpringExtension.class)+@TestInstance(PER_CLASS). Added explicit@Autowired ApplicationContextfield (was previously inherited). AddedLOGfield.TestNGTransactionalSiteIntegrationSetup,TestNGTransactionalAdminIntegrationSetup: replacedextends AbstractTransactionalTestNGSpringContextTestswith@ExtendWith(SpringExtension.class)+@TestInstance(PER_CLASS)+@Transactional.BaseTest: same pattern, added explicit@Autowired ApplicationContext.Individual test classes (~55 files)
@org.testng.annotations.Test→@org.junit.jupiter.api.Test@BeforeClass→@BeforeAll,@AfterClass→@AfterAll,@BeforeMethod→@BeforeEachorg.testng.Assert→org.junit.jupiter.api.Assertions@DataProvider/@Test(dataProvider=...)→@ParameterizedTest+@MethodSource@DataProviderannotations removed from provider classes (methods kept as-is)assertEquals argument order correction
TestNG uses
assertEquals(actual, expected)while JUnit 5 usesassertEquals(expected, actual). Swapped argument order in:RollbackTest.java(1 call)SystemPropertiesTest.java(4 calls)WorkflowTest.java(9 calls)Test method execution ordering
Added
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)and@Order(N)annotations to 21 test classes whose methods depend on execution order (shared state via instance fields). In files that also importorg.broadleafcommerce.core.order.domain.Order, the annotation is fully qualified as@org.junit.jupiter.api.Orderto avoid the name collision.Other fixes
MVELTest.java: changedlogger(inherited fromAbstractTestNGSpringContextTests) toLOG(defined onTestNGSiteIntegrationSetup)CustomerPhoneControllerTest.java: removed unusedMethod testMethodparameter from@BeforeEachmethod to prevent JUnit 5ParameterResolutionException(JUnit 5 cannot resolvejava.lang.reflect.Methodparameters)RegisterCustomerControllerTest.java: added@DisabledtocreateCustomerFromController()— the original TestNG test hadenabled=false, which was not initially migrated, meaning this previously-disabled test would have silently become enabled under JUnit 5Verification
mvn test-compile -pl integrationpasses with zero errorsgrep -r "import org.testng"returns no results across the entire codebaseImportant areas for reviewer attention
assertEquals argument order — The swap from
(actual, expected)to(expected, actual)was done via script matching. Verify the swaps inRollbackTest,SystemPropertiesTest, andWorkflowTestare semantically correct (i.e., the value that was "expected" in the TestNG call is now the first argument).@Orderannotations assume declaration order — The@Order(N)values follow method declaration order in the source file. If the original TestNG execution order differed from declaration order (e.g., viadependsOnMethodsor alphabetical sorting), the@Ordervalues may not reproduce the exact original order. Spot-check classes with complex inter-test dependencies (e.g.,OrderTestwith 22 methods,OfferTestwith 25 methods).@TestInstance(PER_CLASS)on all base classes — This preserves TestNG's default per-class lifecycle (shared instance across test methods). Intentional since many tests share state via instance fields, but verify no test expects per-method isolation.@Transactionalon transactional base classes — Previously inherited fromAbstractTransactionalTestNGSpringContextTests. Should be behaviorally equivalent, but worth a sanity check on rollback behavior.@MethodSourcereferences in parameterized tests — Each@MethodSource("org.broadleafcommerce...ClassName#methodName")must exactly match the provider method. These were bulk-migrated via script. Spot-check a few (e.g.,OrderTest,ProductDaoTest,OfferTest) to confirm correctness.Removed
dependsOnMethods = "springTestContextPrepareTestInstance"— This was a TestNG mechanism ensuring Spring context readiness. JUnit 5'sSpringExtensionhandles this via its own lifecycle callbacks. Should be safe, but worth noting.Removed TestNG
groupsattributes —@Test(groups={"testTranslation"})etc. simplified to plain@Test. If any CI or surefire config filtered on groups, that would need updating. No group filtering was found in the current surefire configuration.@DisabledoncreateCustomerFromController— Only one test hadenabled=falsein the original TestNG code. If other tests were also disabled via a different mechanism (e.g., group exclusion in surefire config), those would not have been caught.Only compile-verified, not runtime-verified —
mvn testwas not run (tests require a full application context with HSQLDB, etc.). Runtime failures from lifecycle differences are possible.Link to Devin session: https://app.devin.ai/sessions/58e44c07b1344020a5249c61c48b44ae
Requested by: @Colhodm