Troubleshooting core tests
This page lists the common problems with core tests, grouped by symptom. Start with the report of the failing class in org.idempiere.test/target/surefire-reports/. Applies to iDempiere 12 and later.
The build is green but no test ran
-DskipTests=falseis missing. Tests are skipped by default.mvn testwas used. Useverifyorinstall; Tycho runs OSGi tests in theintegration-testphase.
A test is not found
- The test uses JUnit 4 imports (
org.junit.Test). Use JUnit 5:org.junit.jupiter.api.Test. - In Eclipse, the class was run as "JUnit Test". Use the
idempiere.unit.testlaunch, or a copy of it with your class selected. See Run from your editor. - A bundle the test needs is missing from
idempiere.unit.test.launch. Add it to the launch.
Tests fail at startup or the context is empty
idempiere.propertiesis missing in the repository root, or the database is not reachable.- The class does not extend
AbstractTestCase, so iDempiere is not started and there is no login context. - A subclass overrides
init(TestInfo)without@BeforeEachor without callingsuper.init(testInfo)first. - Context values are set in
@BeforeAll. They are reset before each test; set them in@BeforeEach.
Many tests fail on a fresh database
Migration scripts are not applied. Run bash RUN_SyncDBDev.sh, then run the tests again.
Record not found, or "Transaction closed"
- A model constructor,
QueryorDBcall getsnullinstead ofgetTrxName(), so it reads or writes outside the test transaction. - A process run by the test commits or closes the test transaction. Keep the process inside the test transaction.
save()returned false without an error. UsesaveEx()to see the reason.
A test passes alone but fails in the full suite
- The test depends on data that another test changed, or on the order of tests.
- A test committed data. Remove
commit(), or clean up in afinallyblock and mark the class@Isolated. - The test depends on today's date.
getLoginDate()is the current time, so it does not help. Set a fixed date on the records, or overridenewLoginDetails(TestInfo)to log in with a fixed date.
A document does not complete or posting is wrong
- Read
info.getSummary()fromrunDocumentActionWorkflow. It gives the reason. - Call
po.load(getTrxName())before you readDocStatusorisPosted(). - For posting, compare with the existing tests in the
acctandcostingpackages.
A mock has no effect
- The
MockedStaticis not open around the call. Use try-with-resources around the code under test. - The stubbed method is a different overload from the one the code calls. Match the arguments, or use
any(). - The code runs on another thread. Static mocks apply only to the current thread.