Skip to content

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 result

A 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 ​

ToolQuestion it answersExample
Syntax check / activationIs this code structurally valid ABAP?>= and > are both valid expressions
ABAP UnitDoes this method behave as specified?Is the total exactly 275 for ten items?
DebuggerWhat happens when the code executes?Did the IF branch run? What was the subtotal?
ATCDoes 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 TESTING identifies the test class and its runnable methods.
  • DURATION SHORT indicates the intended execution time classification.
  • RISK LEVEL HARMLESS indicates that the tests should not affect business data or system settings.
  • exp is the expected result; act is the actual result.
  • The msg provides 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:

  1. A normal case that should obviously work.
  2. A boundary case where a condition changes (9, 10, and 11, for example).
  3. A special case involving a fee or optional flag.
  4. An invalid input, if the method has documented input-handling rules.

For the guided order-total example:

TestExpectedReason
One item, no fee20No discount
Two items plus fee85Delivery must increase the total
Ten items275Discount begins at the boundary
Twelve items, no fee216Discount 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 = 275

One 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 ​

ActionADT location or shortcut
Write local testsABAP class editor → Test Classes tab
Run ABAP UnitRight-click class → Run As → ABAP Unit Test
Run ABAP Unit directlyCtrl+Shift+F10
See test resultsABAP Unit view
Run with coverage, if availableCtrl+Shift+F11
Run console classRun As → ABAP Application (Console) or F9
Set a breakpointDouble-click in the left gutter beside a line
Run ATCRight-click object → Run As → ABAP Test Cockpit
Run ATC directlyCtrl+Shift+F2
Show a missing viewWindow → 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 ​

ActionPurpose
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 viewSee and expand current values
Breakpoints viewDisable 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 ten

and

abap
rv_total = rv_total - iv_delivery_fee. " Subtracts a fee

The 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:

  1. Open its entry in ATC Problems.
  2. Read the check description and affected code line.
  3. Determine whether it is a real issue in your code.
  4. Correct the code, or record why a finding cannot be corrected in the scope of the exercise.
  5. 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 ​

SymptomCheck
ABAP Unit reports zero testsTest code is in the Test Classes tab; class and methods include FOR TESTING; activate the test include
A test returns the wrong resultVerify the business rule, input values, and intermediate calculation
Tests always pass unexpectedlyMake sure you did not change exp to match incorrect code
CL_ABAP_UNIT_ASSERT is unknownConfirm you are in an ABAP Cloud project and the editor recognizes ABAP Unit; inspect the first activation error
Console class does not runConfirm it implements IF_OO_ADT_CLASSRUN and you chose ABAP Application (Console)
Breakpoint is not hitActivate the newest code, enable the breakpoint, and rerun under your own user
ATC option is missingCheck ADT tools and access rights; continue other tasks and record the limitation
SQL table activation failsCheck object names, punctuation, key client, table syntax, and whether the table is in a writable package
SQL counts differEnsure you use your own suffix and table, and that your seed class ran successfully

12. Follow-up questions ​

  1. Why can a program pass syntax checks but fail an ABAP Unit test?
  2. What is the difference between changing an expected result and fixing the code?
  3. Why is an ATC finding different from a failed unit test?
  4. What does the debugger reveal that a test result does not?
  5. Why does a database-side WHERE clause matter?
  6. Why do five demo rows not establish a measurable performance improvement?

Official SAP documentation ​

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.