Skip to Content
author's profile photo Former Member
Former Member

ABAP Unit - Problem


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?



Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Dec 16, 2010 at 02:39 PM

    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.


    Naimesh Patel

    Add a comment
    10|10000 characters needed characters exceeded

    • 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.


      Naimesh Patel

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.