Appearance
Lesson 22 Companion — Testing, Debugging, ATC & Performance
Environment: SAP BTP ABAP Trial + Eclipse ADT
Use with: Lesson 22 guided content and independent practice
This document explains the tools and decisions behind the guided exercise. It is a reference to consult when a test fails, the debugger behaves unexpectedly, or you want to understand a code-quality finding.
1. Why testing belongs in everyday development
Imagine you fix a wrong delivery-fee calculation today. A colleague later changes the discount code, and the fee problem returns. Without tests, the team may only discover it when a user complains again.
ABAP Unit lets you express an expected result in code and check it automatically. A good test is a small, reproducible example of a business rule.
For a calculation method:
text
Inputs → Method being tested → Actual result
↘ compare with expected resultA test fails when the actual result does not match the expected one. Failure is useful information: it gives you a concrete problem to investigate.
2. Four different tools, four different questions
| Tool | Question it answers | Example |
|---|---|---|
| Syntax check / activation | Is this code structurally valid ABAP? | >= and > are both valid expressions |
| ABAP Unit | Does this method behave as specified? | Is the total exactly 275 for ten items? |
| Debugger | What happens when the code executes? | Did the IF branch run? What was the subtotal? |
| ATC | Does this code meet configured technical checks? | Does it use restricted APIs or questionable SQL patterns? |
None of these replaces the others. In particular, ATC is not a business-rule checker, and passing all unit tests does not guarantee performance or security.
3. Read an ABAP Unit test
The minimum ABAP Unit structure is:
abap
CLASS ltc_example DEFINITION FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS example FOR TESTING.
ENDCLASS.
CLASS ltc_example IMPLEMENTATION.
METHOD example.
DATA(actual) = 2 + 3.
cl_abap_unit_assert=>assert_equals(
exp = 5
act = actual
msg = 'Two plus three must equal five' ).
ENDMETHOD.
ENDCLASS.FOR TESTINGidentifies the test class and its runnable methods.DURATION SHORTindicates the intended execution time classification.RISK LEVEL HARMLESSindicates that the tests should not affect business data or system settings.expis the expected result;actis the actual result.- The
msgprovides context when a test fails.
Place local test classes in the Test Classes tab of the ABAP class editor, rather than mixing them into the Global Class tab.
Common assertions
abap
cl_abap_unit_assert=>assert_equals(
exp = 10
act = total ).
cl_abap_unit_assert=>assert_initial(
act = result ).
cl_abap_unit_assert=>assert_not_initial(
act = result ).
cl_abap_unit_assert=>fail(
msg = 'An unexpected branch was executed' ).Choose the assertion that expresses the actual requirement. Never change the expected value just to make a failing test green when the original business rule still applies.
4. How to design useful test cases
A strong introductory test suite covers:
- A normal case that should obviously work.
- A boundary case where a condition changes (
9,10, and11, for example). - A special case involving a fee or optional flag.
- An invalid input, if the method has documented input-handling rules.
For the guided order-total example:
| Test | Expected | Reason |
|---|---|---|
| One item, no fee | 20 | No discount |
| Two items plus fee | 85 | Delivery must increase the total |
| Ten items | 275 | Discount begins at the boundary |
| Twelve items, no fee | 216 | Discount above the boundary |
Two of the original four tests fail by design. Once the implementation is corrected, all four should pass.
5. How to interpret a failing test
Suppose exactly_ten expected 275 but returned 295. That means the program did not apply the 10% discount and subtracted the delivery fee:
text
10 × 30 = 300
No discount applied (incorrect)
300 - 5 = 295 (incorrect)The correct rule is:
text
10 × 30 = 300
300 × 0.90 = 270
270 + 5 = 275One test can expose more than one problem. Use the debugger to inspect the intermediate values rather than only looking at the final difference.
6. Where to find the test tools in Eclipse ADT
| Action | ADT location or shortcut |
|---|---|
| Write local tests | ABAP class editor → Test Classes tab |
| Run ABAP Unit | Right-click class → Run As → ABAP Unit Test |
| Run ABAP Unit directly | Ctrl+Shift+F10 |
| See test results | ABAP Unit view |
| Run with coverage, if available | Ctrl+Shift+F11 |
| Run console class | Run As → ABAP Application (Console) or F9 |
| Set a breakpoint | Double-click in the left gutter beside a line |
| Run ATC | Right-click object → Run As → ABAP Test Cockpit |
| Run ATC directly | Ctrl+Shift+F2 |
| Show a missing view | Window → Show View → Other… |
Menus may differ slightly by the Eclipse/ADT version or user authorizations. Use the menu label when a shortcut is intercepted by the operating system.
7. The debugger: inspect values, not just lines
With a breakpoint in the order-total method, inspect:
iv_unit_price— the price per item;iv_quantity— the quantity being tested;iv_delivery_fee— the fee;rv_total— the total as it changes.
Useful debugger actions
| Action | Purpose |
|---|---|
| Step Over (F6) | Execute the next statement without entering called methods |
| Step Into (F5) | Enter a called method, when available |
| Resume (F8) | Continue until the next breakpoint or completion |
| Variables view | See and expand current values |
| Breakpoints view | Disable or delete breakpoints when done |
If code is running but the debugger does not stop, verify that the breakpoint belongs to the activated code and that the executing request is under the expected user/project context.
8. Guided defect explanation
The two intentional defects were:
abap
IF iv_quantity > 10. " Excludes exactly tenand
abap
rv_total = rv_total - iv_delivery_fee. " Subtracts a feeThe corrected implementation uses >= 10 and + iv_delivery_fee.
The lesson's central skill is not memorizing these operators. It is the process: test, inspect, understand, fix, and retest.
9. ATC: interpreting what your system actually reports
ATC uses a check variant configured in the ABAP system. One environment might report a warning for an example that another environment accepts. It may also return zero findings.
When a finding appears:
- Open its entry in ATC Problems.
- Read the check description and affected code line.
- Determine whether it is a real issue in your code.
- Correct the code, or record why a finding cannot be corrected in the scope of the exercise.
- Run ATC again.
Do not suppress warnings solely to make the results list empty. The aim is to understand the checks.
ATC access, available variants, and result details can depend on your Trial tenant and authorizations. The regular single-object Run As → ABAP Test Cockpit is different from the advanced central custom-code migration ATC scenario, which requires additional landscape connectivity.
10. Performance: SQL is a data-request decision
Consider this business requirement:
“Show order IDs and amounts for high-priority orders.”
Less suitable for large datasets:
abap
SELECT FROM zl22_orders_001
FIELDS *
INTO TABLE @DATA(all_orders).
LOOP AT all_orders INTO DATA(order_row)
WHERE priority = 'H'.
" Process the selected data in ABAP.
ENDLOOP.Better aligned with the requirement:
abap
SELECT FROM zl22_orders_001
FIELDS order_id, amount
WHERE priority = 'H'
INTO TABLE @DATA(high_priority_orders).The second form lets the database restrict both rows and columns before transferring results. This aligns with SAP's ABAP SQL performance advice.
Caveat: This is a design comparison, not proof of an exact millisecond gain. For serious performance tuning, gather representative measurements with an ABAP trace or SQL analysis tool available in your system.
Why this relates to Lesson 21
An OData request that specifies a filter and set_top( ) follows the same idea: do not fetch unnecessary records only to discard them afterward.
11. Troubleshooting guide
| Symptom | Check |
|---|---|
| ABAP Unit reports zero tests | Test code is in the Test Classes tab; class and methods include FOR TESTING; activate the test include |
| A test returns the wrong result | Verify the business rule, input values, and intermediate calculation |
| Tests always pass unexpectedly | Make sure you did not change exp to match incorrect code |
CL_ABAP_UNIT_ASSERT is unknown | Confirm you are in an ABAP Cloud project and the editor recognizes ABAP Unit; inspect the first activation error |
| Console class does not run | Confirm it implements IF_OO_ADT_CLASSRUN and you chose ABAP Application (Console) |
| Breakpoint is not hit | Activate the newest code, enable the breakpoint, and rerun under your own user |
| ATC option is missing | Check ADT tools and access rights; continue other tasks and record the limitation |
| SQL table activation fails | Check object names, punctuation, key client, table syntax, and whether the table is in a writable package |
| SQL counts differ | Ensure you use your own suffix and table, and that your seed class ran successfully |
12. Follow-up questions
- Why can a program pass syntax checks but fail an ABAP Unit test?
- What is the difference between changing an expected result and fixing the code?
- Why is an ATC finding different from a failed unit test?
- What does the debugger reveal that a test result does not?
- Why does a database-side
WHEREclause matter? - Why do five demo rows not establish a measurable performance improvement?
Official SAP documentation
- ABAP Unit Test Classes in Eclipse ADT
- Running ABAP Unit Tests
- Debugging ABAP Code
- ATC Check Runs in ADT
- ABAP SQL Performance Notes
- SAP Tutorial — ABAP Unit Test for RAP
Verification limit: These syntax and UI instructions were cross-checked against SAP references. The code samples have not been compiled or executed in your individual Trial tenant; follow the acceptance checks in the main lesson to establish that final verification.