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

ABAP Unit Tests

Former Member
0 Likes
1,669

Hi,

I'm new to ABAP. Since some days I'm evaluating ABAP Unit Tests (for ABAP Objects).

I wrote a class Z_XY and then I wrote an ABAP Unit Test class Z_XY_TEST with several test methods which test all methods of class Z_XY.

In principle everything works fine. All tests deliver the results I expect when I run the unit test on the test class.

The only thing that confuses me is the warning "The global test class <Z_XY_TEST> is not abstract." that appears in the dialog "ABAP Unit: Result Display".

This warning seems to prevent the test from getting a green "LED" on the highest level ("TASK..."). Additionally, the tests cannot be run if the "Limit of Risk Level" is set to another value as "Harmless" because: "No execution as acutal risk level is too high", so that I cannot use another risk level limit than "Harmless".

When I switch the instantiation of the test class to "Abstract" absolute no tests are executed (not surprising...).

Can anyone tell me what I'm doing wrong?

Thank you in anticipation,

Regards,

Eike Menking

Edited by: Eike Menking on Jan 22, 2010 4:06 PM

1 ACCEPTED SOLUTION
Read only

naimesh_patel
Active Contributor
0 Likes
1,249

When you use the Global Test class, ideally you should do is:

Create your Production Class (Z_XY)

Create your Global Text Class by selecting the Unit Test Class (Z_XY_TEST). This must not be FINAL.

You create the test methods, which we would like to execute. Make them as Protected.

Now, go to Production Class and create local test class. Use Utilities > Test Class Generation

In your generated local test class definition, inherit it from the Global Test Class Z_XY_TEST).

Implement new methods or redefine your existing methods.

Run the Unit Test .

Ideally, the global test class should be Abstract as, you are not supposed to instantiate that class. ABAP Unit Framework would do it for you.

I tried all these steps (with Abstract and without abstract) but I didn't get the specified information message. Are you doing something else ?

Regards,

Naimesh Patel

4 REPLIES 4
Read only

naimesh_patel
Active Contributor
0 Likes
1,250

When you use the Global Test class, ideally you should do is:

Create your Production Class (Z_XY)

Create your Global Text Class by selecting the Unit Test Class (Z_XY_TEST). This must not be FINAL.

You create the test methods, which we would like to execute. Make them as Protected.

Now, go to Production Class and create local test class. Use Utilities > Test Class Generation

In your generated local test class definition, inherit it from the Global Test Class Z_XY_TEST).

Implement new methods or redefine your existing methods.

Run the Unit Test .

Ideally, the global test class should be Abstract as, you are not supposed to instantiate that class. ABAP Unit Framework would do it for you.

I tried all these steps (with Abstract and without abstract) but I didn't get the specified information message. Are you doing something else ?

Regards,

Naimesh Patel

Read only

0 Likes
1,249

Thank you for your helpful answer.

My failure was: I created an ABAP Unit Test class on my own instead of using the "Utilities->Test Class Generation" and implemented all tests on my own. Works as well except for this "Abstract Global Test Class"-Problem.

As I said it before: I'm new to the ABAP world...

Regards,

Eike Menking

Read only

0 Likes
1,249

Hello Eike,

the ABAP Unit philosophy is that local unit test classes reside within the program they test. Global Test Classes are intended solely for reuse purposes. An global test class that is not abstract is most likely checking something else. To prevent people to write test which don´t adhere to the unit test philosphy of ABAP Unit there is this little reminder :)=

Best Regards

Klaus

Read only

Former Member
0 Likes
1,249

Hi Eike,

I wrote a class Z_XY and then I wrote an ABAP Unit Test class Z_XY_TEST with several test methods which test all methods of class Z_XY.

In principle everything works fine. All tests deliver the results I expect when I run the unit test on the test class.

The only thing that confuses me is the warning "The global test class <Z_XY_TEST> is not abstract." that appears in the dialog "ABAP Unit: Result Display".

Please take a look at the documentation:

http://help.sap.com/abapdocu_70/en/ABAPCLASS_FOR_TESTING.htm

In particular:

As of Release 7.0, you can create global test classes for re-using complex test preparations. Global test classes should always be abstract and can only be used in local test classes. All instance methods of a global test class are currently automatic test methods.

To navigate to a local test class, open your ABAP Class > Goto > Local Test Classes (NW 7.0)

or Goto > Local Definitions/Implementations > Local Test Classes (NW 7.0.2+)

Kind regards,

Hristo