Application Development 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: 

ABAP Unit - Problem

Former Member
0 Kudos

Hi!

I have created a test class with a instance attribute typed with a local class of the main program, a setup method preparing some data and two methods for testing. In the first method for testing I instantiate the instance attribute, and when I try to access it in the second method for testing, I get a CX_SY_REF_IS_INITIAL exception.

Debugging the first method for testing shows that the object is instantiated correctly (no exception occurs).

What could the problem be?

Regards,

Thomas

1 ACCEPTED SOLUTION

naimesh_patel
Active Contributor
0 Kudos

You should use the SETUP method to instantiate the Testable object. The purpose of the SETUP method is to prepare the fixture for the test. This SETUP method would get triggered before each test method call by the ABAP Unit Test Framework. Since it is being called every time, it would instantiate the Object every time the SETUP method is called.

If you wish to use the same instance of the object, you should instantiate the testable object in the method CLASS_SETUP. This method would be called once for each test class.

Regards,

Naimesh Patel

3 REPLIES 3

naimesh_patel
Active Contributor
0 Kudos

You should use the SETUP method to instantiate the Testable object. The purpose of the SETUP method is to prepare the fixture for the test. This SETUP method would get triggered before each test method call by the ABAP Unit Test Framework. Since it is being called every time, it would instantiate the Object every time the SETUP method is called.

If you wish to use the same instance of the object, you should instantiate the testable object in the method CLASS_SETUP. This method would be called once for each test class.

Regards,

Naimesh Patel

0 Kudos

Transferring object instation to the setup-method worked out perfectly. Thank you very much. Just an additional question: How is the sequence determined, in which the testing-methods are executed?

0 Kudos

How is the sequence determined, in which the testing-methods are executed?

I thought that you would be assuming the methods would be called in the sequence they are defined, when you raised the question about getting the NULL object exception.

The sequence it being determined internally. I remember reading somewhere that tests should not be dependent on the sequence of the test methods. In other words, we should not be using the output of one test method as the input of the second test method because this sequence is being determined internally. Generally, it is sorted by the Name but still we must try to design our test as individual test.

Regards,

Naimesh Patel