2010 Sep 10 1:57 PM
Hello ABAPers!
I created a new Z-class (ex: ZCL_REP) and also created a Z-dialog (SAPMZREP) that will be using this object class.
I also created an ABAP Unit test class in order to test my class methods. I am wondering where should this AU test class code reside... the options I see are:
a) inside my module pool SAPMZREP as an include
b) in a different Z-program completely
Where is the best place to store this test code ?
Thanks in advance !
José
2010 Sep 10 2:08 PM
It depends on how you want to compile it.
If you put the include in the module pool, if you change something in the module pool that causes a syntax error in the test class, you must fix the test class to finish compilation of the code. (You should update your test class anyway so it shouldn't be an issue)
If you put the include outside the module pool, you may have inconsistancies between the abap unit class and the tested code but you don't necessarily have to keep the test class updated.
At first I thought it didn't matter but after writing it out, I think it's best to keep it in the module pool.
2010 Sep 10 2:17 PM
I would say, inside your ZCL_REP class as local test class. You should have all the logic which you want to test using the Unit Test inside your class ZCL_REP.
Regards,
Naimesh Patel
2010 Sep 10 2:26 PM
Hi Naimesh,
Thanks for your answer and I like the idea of keeping "Unit Testing code" close to my Object Class ZCL_REP since this is exactly what my test code is actually testing. However, how can I attach my test code to the object class since an object class, as far as I know, is not a "program" where I can attach an include to it. When I am in "Class Builder" or "Object navigator (SE80)", can you tell me how I can insert my test class code to the "ocject class" itself... ?
José
2010 Sep 10 2:42 PM
If you are on ABAP Release 700 or higher, you can use the option Utilities > Test Class Generation in the SE24. This will give you popup to select the "production" ( - testable) method for which you want to create the Local Test Class. Once the test class is generated, you can navigate to test class using Go to > Local Test Classes.
If you are on ABAP Release 640, you don't have the Local Test Class include nor the Test class generation wizard. So, you need to use the "Local Types" to define your test class and "Implementation" to implement the test class.
If you need to get an access to Private attribute or methods, you need to use the FRIENDS. Check answer from Klaus in the thread .
Regards,
Naimesh Patel
2010 Sep 23 7:06 PM
That worked and solved my problem... Thanks a lot !