Now accepting guest editorial from SAP, Oracle, Workday and ServiceNow practitioners.Pitch a guide
The Sign-Off Table

Lesson 5 of 6

Testing generated apps: from generated tests to real evidence

9 min

Listen to this lesson

0:00 / 6:29

Joule can generate unit tests for CAP application logic, and a coding agent can write more. That's useful, and it's also a trap: tests generated from the code tend to confirm what the code does, not what the business needs. This lesson shows how to use generated tests as a starting point and turn them into evidence a test lead can sign.

Generating tests in SAP Build Code

SAP documents the flow: from the Application Logic Editor, open the code editor for unit tests, agree to enable the test environment, enter a prompt or keep the default, and accept the result. Then, in the Generative AI-Powered Development guide, run the test; the required npm dependencies are installed and the test runs through npm test. The tests use CAP's test support, cds.test, which starts a CAP server for the project and gives you HTTP helpers such as GET and POST, an expect function and data.reset to restore the database between tests. CAP documents it for the Node.js test runner, Jest, Mocha and Vitest.

Generated tests are the first layer; negative, boundary, authorization and state tests turn them into evidence.
The Sign-Off Table · thesignofftable.com/academy/sap-aid-205

What generated tests usually miss

GapExample in the claims appTest to add
Negative inputClaim without failure datePOST without failureDate returns an error, not a crash
BoundariesFailure exactly 24 months agoClaims at 24 months minus one day, exactly 24 months, plus one day
State transitionsNEW straight to APPROVEDApprove from NEW is rejected; from IN_REVIEW it succeeds
AuthorizationA viewer approves a claimRequests as a user without ClaimProcessor get 403
Data typesDates compared as stringsFailure dates across a month and year boundary
CompositionDeleting a claim with itemsItems are deleted with the claim; no orphans remain

Typical gaps in generated tests for CAP services, with tests that close them.

Two of these found real bugs in Elena's app. The date comparison treated failure dates as text, so "2025-1-05" style values sorted wrongly when data came from an upload; and the approve handler checked the status but not the user's role, relying on the UI to hide the button. Both fixes came with tests that fail on the old code, which is the simplest proof that a test tests something.

Reviewing tests written by AI

  • Read the assertions first. A test with no meaningful assertion, or one that asserts whatever the code returned, proves nothing.
  • Watch for rewritten expectations. If the agent changed an expected value to make a test pass, ask why; that's the most common way generated tests hide defects.
  • Check the data. Tests that pass only with the sample CSV are fragile; reset and create the data each test needs.
  • Break the code on purpose. Comment out a rule and run the tests. If nothing fails, the rule isn't tested.
  • Keep tests independent. Use data.reset between tests so order doesn't matter.
Generated, weakSmoke value only; don't count it as evidence
Written, weakRare but real: tests written in a hurry; fix the assertions
Generated, strongReviewed and kept; counts once someone has broken the code and seen it fail
Written, strongThe core of the evidence pack: rules, boundaries, authorization
What counts as evidence depends on assertion strength and review, not on who typed the test.
The Sign-Off Table · thesignofftable.com/academy/sap-aid-205

Above the unit level

Unit tests with cds.test cover the service. Priya's team still runs end-to-end scenarios in cmc-ext-test against CMQ client 100 through the CMC_S4HANA destination once the app reads customer data from S/4HANA: a claim for Great Lakes Fleet Services, its review and approval, and a rejected claim older than 24 months. For UI-level automated checks of Fiori elements and UI5 apps, SAP's documentation describes OPA5 integration tests; whatever tool runs them, the scenarios and expected results come from the business rules, not from the generated code.

Keep the test data honest. Generated sample data is fine for unit tests, as long as it is invented and its edge cases are deliberate. End-to-end data in cmc-ext-test should come from CMQ client 100's test master data, not from production copies, and claims created there should be cleaned up after each run so tests don't pass because of leftovers from the previous day.

What would you do?

Joule generated eight unit tests for the approve handler, and all pass. Elena comments out the check that a claim must be IN_REVIEW before approval and reruns: all eight still pass. What does this tell her, and what should she do?

Key points
  • Joule generates CAP unit tests that run with npm test; they are a starting point.
  • cds.test starts the CAP server and offers GET, POST, expect and data.reset for independent tests.
  • Add negative, boundary, state, authorization and composition tests; break the code to prove a test works.
  • Unit tests prove the service; business scenarios in the test subaccount prove the process.

Check your understanding · not graded

Lesson check

  1. 1. How do Joule-generated unit tests run in SAP Build Code?

  2. 2. What does data.reset do in a cds.test-based test?

  3. 3. How can you prove that a test really checks the 24-month rule?

  4. 4. An agent changed an expected value so a failing test passes. What should the reviewer do?