Skip to content

Migrate all TestNG tests to JUnit 5#10

Open
devin-ai-integration[bot] wants to merge 3 commits intodevelop-7.0.xfrom
devin/ticket-4.1-testng-to-junit5
Open

Migrate all TestNG tests to JUnit 5#10
devin-ai-integration[bot] wants to merge 3 commits intodevelop-7.0.xfrom
devin/ticket-4.1-testng-to-junit5

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Apr 17, 2026

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)

  • Removed org.testng:testng:7.8.0 dependency
  • Removed surefire-testng provider from maven-surefire-plugin (kept surefire-junit-platform)
  • Added junit-jupiter:5.10.2 and junit-jupiter-params:5.10.2
  • Removed exclusions of junit-jupiter-api and junit-jupiter-engine from spring-boot-starter-test

Base test classes (5 classes)

  • TestNGSiteIntegrationSetup, TestNGAdminIntegrationSetup: replaced extends AbstractTestNGSpringContextTests with @ExtendWith(SpringExtension.class) + @TestInstance(PER_CLASS). Added explicit @Autowired ApplicationContext field (was previously inherited). Added LOG field.
  • TestNGTransactionalSiteIntegrationSetup, TestNGTransactionalAdminIntegrationSetup: replaced extends AbstractTransactionalTestNGSpringContextTests with @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@BeforeEach
  • org.testng.Assertorg.junit.jupiter.api.Assertions
  • @DataProvider / @Test(dataProvider=...)@ParameterizedTest + @MethodSource
  • @DataProvider annotations removed from provider classes (methods kept as-is)

assertEquals argument order correction

TestNG uses assertEquals(actual, expected) while JUnit 5 uses assertEquals(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 import org.broadleafcommerce.core.order.domain.Order, the annotation is fully qualified as @org.junit.jupiter.api.Order to avoid the name collision.

Other fixes

  • MVELTest.java: changed logger (inherited from AbstractTestNGSpringContextTests) to LOG (defined on TestNGSiteIntegrationSetup)
  • CustomerPhoneControllerTest.java: removed unused Method testMethod parameter from @BeforeEach method to prevent JUnit 5 ParameterResolutionException (JUnit 5 cannot resolve java.lang.reflect.Method parameters)
  • RegisterCustomerControllerTest.java: added @Disabled to createCustomerFromController() — the original TestNG test had enabled=false, which was not initially migrated, meaning this previously-disabled test would have silently become enabled under JUnit 5

Verification

  • mvn test-compile -pl integration passes with zero errors
  • grep -r "import org.testng" returns no results across the entire codebase

Important areas for reviewer attention

  1. assertEquals argument order — The swap from (actual, expected) to (expected, actual) was done via script matching. Verify the swaps in RollbackTest, SystemPropertiesTest, and WorkflowTest are semantically correct (i.e., the value that was "expected" in the TestNG call is now the first argument).

  2. @Order annotations 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., via dependsOnMethods or alphabetical sorting), the @Order values may not reproduce the exact original order. Spot-check classes with complex inter-test dependencies (e.g., OrderTest with 22 methods, OfferTest with 25 methods).

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

  4. @Transactional on transactional base classes — Previously inherited from AbstractTransactionalTestNGSpringContextTests. Should be behaviorally equivalent, but worth a sanity check on rollback behavior.

  5. @MethodSource references 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.

  6. Removed dependsOnMethods = "springTestContextPrepareTestInstance" — This was a TestNG mechanism ensuring Spring context readiness. JUnit 5's SpringExtension handles this via its own lifecycle callbacks. Should be safe, but worth noting.

  7. Removed TestNG groups attributes@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.

  8. @Disabled on createCustomerFromController — Only one test had enabled=false in 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.

  9. Only compile-verified, not runtime-verifiedmvn test was 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


Open with Devin

- 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>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

devin-ai-integration[bot]

This comment was marked as resolved.

…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>
devin-ai-integration[bot]

This comment was marked as resolved.

- Add @disabled annotation to createCustomerFromController() in RegisterCustomerControllerTest
  (original TestNG test had enabled=false which was not migrated)
- Remove extra blank lines between @order and @Test/@ParameterizedTest annotations

Co-Authored-By: Arjun Mishra <arjunsaxmishra@gmail.com>
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.

1 participant