Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Syntax Error: May not use object or type

Former Member
0 Likes
630

Hi,

When I try to make a method call to a static method

I get the following syntax error:

Include Z_TEST_FRAMEWORK_TOP

(E) Package "TESTFRAMEWORK" must not use object "CLAS CL_AUNIT_ASSERT CLAS" from Package "SABP_UNIT_CORE_API" in one of the following ways:

"Use object or type"

The original message in German:

Include Z_TEST_FRAMEWORK_TOP

(E) Paket "TESTFRAMEWORK" darf das Objekt "CLAS CL_AUNIT_ASSERT CLAS"

aus Paket "SABP_UNIT_CORE_API" in keiner der folgenden Arten verwenden:

"Use object or type"

I try to write a unit test in ABAP Unit.


*&---------------------------------------------------------------------*
*& Include Z_TEST_FRAMEWORK_TOP                              Report Z_TEST_FRAMEWORK_P
*&
*&---------------------------------------------------------------------*

REPORT   Z_TEST_FRAMEWORK_P.

CLASS ZCalculator DEFINITION.
  PUBLIC SECTION.
    METHODS:
      constructor,
      type_in IMPORTING x TYPE i,
      add IMPORTING x TYPE i,
      sub IMPORTING x TYPE i,
      get_res RETURNING value(r) TYPE i.

  PRIVATE SECTION.
    DATA:
      res TYPE i. "The Value shown on the calculators display.

ENDCLASS.

START-OF-SELECTION.

WRITE 'Running Calculator Test'.
DATA: lv_calc TYPE REF TO ZCalculator.
CREATE OBJECT lv_calc.
CALL METHOD lv_calc->type_in( 5 ).
CALL METHOD lv_calc->add( 3 ).

DATA: lv_res TYPE i.
lv_res = lv_calc->get_res( ).
WRITE: /, 'LV_RES= ', lv_res.

CLASS ZTestCalculator DEFINITION
                      FOR TESTING
                      RISK LEVEL HARMLESS
                      DURATION SHORT.
  PRIVATE SECTION.
    DATA: lo_calc TYPE REF TO ZCalculator.

    METHODS:
      setup FOR TESTING,
      test_type_in FOR TESTING,
      test_add     FOR TESTING,
      test_sub     FOR TESTING,
      test_get_res FOR TESTING.
ENDCLASS.

CLASS ZCalculator IMPLEMENTATION.
  METHOD constructor.
    res = 0.
    "WRITE: /, 'RES= ', res.
  ENDMETHOD.

  METHOD type_in.
    res = x.
    "WRITE: /, 'RES= ', res.
  ENDMETHOD.

  METHOD add.
    res = res + x.
    "WRITE: /, 'RES= ', res.
  ENDMETHOD.

  METHOD sub.
    res = res - x.
    "WRITE: /, 'RES= ', res.
  ENDMETHOD.

  METHOD get_res.
    r = res.
  ENDMETHOD.
ENDCLASS.

CLASS ZTestCalculator IMPLEMENTATION.
  METHOD setup.
    CREATE OBJECT lo_calc.
  ENDMETHOD.

  METHOD test_type_in.
    DATA: lv_res TYPE i.
    lv_res = lo_calc->get_res( ).

    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).
    lo_calc->type_in( x = 5 ).
    lv_res = lo_calc->get_res( ).
    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 5 ).

  ENDMETHOD.

  METHOD test_add.
    DATA: lv_res TYPE i.
    lv_res = lo_calc->get_res( ).

    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).
    lo_calc->type_in( x = 5 ).
    lo_calc->add( x = 5 ).
    lv_res = lo_calc->get_res( ).
    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 11 ).
  ENDMETHOD.

  METHOD test_sub.
    DATA: lv_res TYPE i.
    lv_res = lo_calc->get_res( ).

    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).
    lo_calc->type_in( x = 5 ).
    lo_calc->sub( x = 5 ).
    lv_res = lo_calc->get_res( ).
    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).
  ENDMETHOD.

  METHOD test_get_res.
    DATA: lv_res TYPE i.
    lv_res = lo_calc->get_res( ).

    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).
    lo_calc->type_in( x = 5 ).
    lv_res = lo_calc->get_res( ).
    cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 5 ).
  ENDMETHOD.
ENDCLASS.

The error happens in first line where the test method calls:

cl_aunit_assert=>assert_equals( ACT = lv_res EXP = 0 ).

[/code]

The error does not happen if I remove all cl_aunit_assert=>assert_equals from my test class.

Do I have to import the ABAP Unit Package before I can use it in my project?

I am a abap novice, how can I import a package?

Could it be possible that my project does not have enough permissions to call a method from ABAP Unit or other projects?

Thanks Yours,

Tom

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
594

No need to import anything, but I see something interesting in your coding, can you please tell me what NetWeaver release you are using?

Regards,

Rich Heilman

Read only

0 Likes
594

My SAP's component version is ...

Message was edited by:

Tom Dinkelaker

Read only

0 Likes
594

You on ramp-up?

Regards,

RIch Heilman

Read only

0 Likes
594

Ahh, I see that you are an SAP employee, you would probably get better support on this issue internally since 7.10 is only in ramp-up.

Regards,

RIch Heilman