Questions about ABAP Unit (Integrate in class / encapsulate DB access)

Hi,
i have allready done some Unit Tests. Till this post i have created a report and put my test class definition / implementation there. The report is just a wrapper for testing. The functionallity is impelemented in classes.
My first Question is how to integrate the test code in my class. In all examples they put the code beneath the class implementation. How do i get there? In se80 i can only see the public definition.
The other question is about testing methods, which contains database access. How can i encapsulate the db access for tests. I read abput implementing a seperate class, which handles all db related actions.
Bye Richard.

Hello Richard,
it is recommended to keep the domain code and the test code within the same program. Depending on the release in use a Class-Pool (program) offers an implementation include (for any local class) or possibly also a dedicaded test class include.
Put the definition and the implementation of your unit test into one of this includes.
In case your code under test has hard to test dependencies you need to break them. After the hard to test dependency (such as repository access) is separated it can be replaced by use of test doubles (see also http://www.xunitpatterns.com).
Propably the following approach is the easiest one:
- put any db access into a separate method
- create a local subclass as test double that overwrites exactely the db access methods with test friendly code
- run your unit test logic against this local test double
The say "cleaner" way is to:
- separate the db access to a dedicated repository service class (with instance methods of course).
- create a test double of this repository class
- use the technique "dependency injection" and run your test
Best Regards
  Klaus

Similar Messages

  • Hi Experts, questions about abap unit test(abap oo)?

    Hi Experts,
    I am learning abap unit test, could you please tell me some info about how I can test the performance of some specific code in my program? can abap unit test do this kind of job? and could you please tell me what I can do using abap unit test? and some classic examples are appreciated, thanks in advance!
    Kind regards
    Dawson

    Hi
    Below documents will give you more information,
    http://help.sap.com/saphelp_nw04/helpdata/en/a2/8a1b602e858645b8aac1559b638ea4/content.htm
    ABAP Testing and Troubleshooting [original link is broken]
    http://bi.offis.de/publicProject/g16cglafhqva.htm
    regards
    Nagaraju

  • Design question about when to use inner classes for models

    This is a general design question about when to use inner classes or separate classes when dealing with table models and such. Typically I'd want to have everything related to a table within one classes, but looking at some tutorials that teach how to add a button to a table I'm finding that you have to implement quite a sophisticated tablemodel which, if nothing else, is somewhat unweildy to put as an inner class.
    The tutorial I'm following in particular is this one:
    http://www.devx.com/getHelpOn/10MinuteSolution/20425
    I was just wondering if somebody can give me their personal opinion as to when they would place that abstracttablemodel into a separate class and when they would just have it as an inner class. I guess re-usability is one consideration, but just wanted to get some good design suggestions.

    It's funny that you mention that because I was comparing how the example I linked to above creates a usable button in the table and how you implemented it in another thread where you used a ButtonColumn object. I was trying to compare both implementations, but being a newbie at this, they seemed entirely different from each other. The way I understand it with the example above is that it creates a TableRenderer which should be able to render any component object, then it sets the defaultRenderer to the default and JButton.Class' renderer to that custom renderer. I don't totally understand your design in the thread
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=680674
    quite yet, but it's implemented in quite a bit different way. Like I was saying the buttonClass that you created seem to be creating an object of which function I don't quite see. It looks more like a method, but I'm still trying to see how you did it, since it obviously worked.
    Man adding a button to a table is much more difficult than I imagined.
    Message was edited by:
    deadseasquirrels

  • Two Questions on ABAP UNIT

    I'm familiar with the technical concept of ABAP Unit testing, using both local or global classes, running sets of Unit Tests using the Code Inspector. However, I'm struggling with two issues:
    a) Technical issue: how can I test a Protected or Private method of a class using ABAP Unit testing? It works if the class to be tested has granted friendship to the unit test class, but is that the way to do this?
    b) conceptual issue on the types of Unit Tests to define: the Unit Test is based on comparing actual results with expected results. But how can I predict a result on a development environment that is constantly changing?
    Thanx in advance
    Ben Meijs

    Hi!
    For having plan vs actual report, first of all you need to define CO versions through ORKE for your operating concern. You also needs to define plan version through KE14. Also you need to assign COPA reciever plan version for integrated planning.
         All your SD condition types need to be assigned to value fields. Also to flow actual values of production orders, CO Orders - it is required to assign PA transfer structure to settlement profile. Settlement profile must allow profitlability segments as settlement recievers and it must be stored in settlement profile. The assignment ensures that variances also flows to COPA. Key figure should also be defined for when assessment is caried out from cost center accounting to COPA. Also your value fields are also to be assigned to Cost component structure in COPA.
           After doing above necessary activity, you may plan for your form of report through KE34. Lines, form and header are specified by means of characteristics or value fields.
    Hope it helps a lot!
    Please revert back for any query.
    Thanks & Regards,
    Taral Patel

  • Questions about the future directions of InfoPath and Microsoft Access

    Because I have been confused about the future directions of InfoPath and Access, I wrote a short blog post, which I have pasted below.  My question is, can Microsoft provide some more guidance on Access vs InfoPath?  If Access is indeed the
    the future direction, can you please provide some pointers to resources that can help us transition.
    A Short Review of MS Access,  SharePoint ,InfoPath (2013)
    After the November 2012 SharePoint Conference in Las Vegas (#spc12) there were a number of blog posts and people saying that Access 2013 was great and would be replacing InfoPath.
    Marc Anderson and
    Ruven
    Gotz have short posts summarizing #SPC12 and touch on the subject of InfoPath and Access.  I also spoke with several individuals shortly after #SPC12 and they were excited about Access 2013.
    Since I rely heavily on InfoPath for much of what I do, I wanted to kick the tires and see what everyone was talking about.  First, a few notes about SharePoint 2013 and Office 2013.
    Microsoft should rename Access:  If you have tried to
    bing the word Access, then you know that the search results are overwhelming,  because the word "access" is used for so many other purposes.
    Use the RTM version of Office 2013! I was performing  my investigations by leveraging the Office 365 Beta and the Office Applications that come with it.  Not much was working!  After I uninstalled the Beta
    version of Office 2013 and Installed the RTM version everything seemed to work. 
    Windows 7 and IE 9.0: The drag & drop that is being touted as
    "manna from heaven" seems to work well with Firefox, Safari, Chrome, and IE 10, but it does
    not work with IE 9!
    Non Microsoft browsers are still second class citizens (except for the drag & drop):  Microsoft has finally done away with the Active X's for datasheet view (that is brilliant!)  One can now see the newly
    minted datasheet view in many browsers.  But I still find that one needs to be in IE to do a number of key manual opeartions.  For example pasting numerous rows of data from a spreadsheet into the new sheet view works only in IE.
    Access 2013
    Microsoft Access is touted as a non developer tool.  I know a number of people who are on the business side and love Access.  These people will like the renewed energy that Microsoft has applied to Access.   One should note that conceptually
    this functionality existed  in SharePoint 2010.  Here is what I see that is new:
    +The new version works better:Although I haven't tested it fully, it seems that many more features that work on the Desktop version of Access, now work in the published Web Application which is hosted by SharePoint 2013.
    +The new version has fairly robust browser based forms: End users can now fill in data using forms that are rendered in the browser.
    +The published version that resides in SharePoint now uses its own SQL server tables.  So the engine appears to be SQL Server, not a modified version of Access built for a server.  This stands to be quite robust, but I imagine
    that some quirks will surface due to new model.
    The limitations are:
    - Access is pretty much its own application and does not integrate with SharePoint building blocks.  For example, an Access table is not easy to integrate with a SharePoint workflow.  Further, although  Access forms now are visible
    in a browser, they are not nearly as rich as InfoPath forms.  InfoPath forms cannot easily integrate with the Access tables.  In order to integrate SharePoint features and Access, one needs to tie SharePoint list(s) to Access as data sources. 
    This overcomplicates the model and one may very well run into synchronization issues.
    In short, although I believe there will be some people who will be happy with newly minted Access, I do not think that Access will be able to replace InfoPath and Workflow technologies.  I do agree that Microsoft does not seem to have put much energy into
    InfoPath.  If they leave a vacuum in this space, then others may very well take over, for instance Nintex Forms.

    Although I agree with the comments made by Ruven and Marc after the conference please note that those blog posts are their own personal opinions and that they don't work for Microsoft.  A lot of people have asked Microsoft to clarify the future of InfoPath
    and the response up until now has been a deafening silence.  In my opinion speculations about Access replacing InfoPath are premature.
    I should also point out that most of your comments about Access 2013 above are actually about Access Services in SharePoint Server 2013.  Access Services are NOT Access they are a shared service offering in SharePoint that convert and publish Access
    databases and forms.  As you point out once an Access database is published through Access services it is converted to SQL Server and no longer resides in Access.  Of course I don't work for Microsoft either so these are all just my personal opinion. 
    Having said that I doubt you will get the confirmation/response that you are hoping for from any official Microsoft channel.
    Paul Stork SharePoint Server
    MVP Principal Solutions Architect: BlueChip Consulting Group
    Blog: http://dontpapanic.com/blog
    Twitter: Follow @pstork
    Please remember to mark your question as "answered" if this solves your problem.

  • Questions about ABAP 7.02 Trial and CE 7.2 Trial

    Hello,
    I am interested in setting up a java and abap stack to try out some of the newer technologies.
    Can I install ABAP 7.02 Trial and CE 7.2 Trial and have them interact (WD4J accessing ABAP backend)?
    Also is there a way to extend the licenses for the two application server trials?  When I visit https://websmp230.sap-ag.de/sap%28bD1lbiZjPTAwMQ==%29/bc/bsp/spn/minisap/minisap.htm, I do not see these two listed.  Will I be able to use one of the other systems to extend the license?
    If these are not a good choice for what I need, what versions would you recommend?  I will be installing on my notebook running Windows Vista with 3GB of RAM.
    Thanks,
    Steven

    Hello,
    I'm also interested in issues that you've asked. I would like to install java stack on ABAP trial Netweaver, but I've found somewhere that since ECC6.0 SAP is proposing to install separate java system instead of doing dual stacking. However I've found this info in only one place, so I'm not sure if it's 100% true.
    I think it should be possible to make these 2 systems talk to each other, but as in your case, my PC is to weak to run two SAP instances. ABAP needs at least 1GB on XP and 2GB on VISTA and JAVA if I remember correctly 2GB on XP and more on VISTA. So I think that you won't be able to run both of them in the same time.
    And about license, yes it is possible. Check this site http://tonkapome.wordpress.com/2009/07/04/sap-netweaver-trial-version-license-renewal/
    I did it for my 7.2 NSP system and it worked. I didn't try it for CE1, but since it is on this list you should be able to do it without any problems. I don't know why but after this update my developer user BCUSER has lost developer key so I had to input it once again, but beside this everything works fine.
    Best regards
    Marcin Cholewczuk

  • Question about writeObject/readObject and descendants classes

    Hello to all,
    I have a doubt about how class serialization is done that I'd like to remove.
    I wrote a class (called "A") that implements Serializable interface and, according to java documentation, I implemented the methods read/writeObject and all seem work well.
    Now I would know if I have to copy and paste the same methods also in classes that are instantiated into my A class or it is not necessary.
    This is an example code:
    public class A implements Serializable {
    private B Bclass;
    private void writeObject(ObjectOutputStream out) throws IOException {...}
    private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {...};
    public A() {
    B = new Bclass(1,2,3);
    public class B implements Serializable {
    private int a,b,c;
    private C Cclass;
    public B(int a, int b, int c) {
    this.a = a;
    this.b = b;
    this.c = c;
    C = new Cclass(a,b);
    public class C implements Serializable {
    private int a,b;
    public C(int a, int b) {
    this.a = a;
    this.b = b;
    this.c = c;
    }Is it necessary add read/writeObject methods also in "B" and "C" classes?
    Thank you in advance for your answers.
    Kind Regards,
    Antonio.

    Antonio.A wrote:
    The only thing that I do is (d)encrypt in a special manner the (In|Out)put object Stream (and all works well).
    The problem is not the method's implementation, but if I have to copy and paste read/writeObject also in the classes initialized into the root class of serialized tree.if i understand correctly, you want to serialize some graph of objects, encrypt that, and then write the encrypted data to the actual ObjectOutputStream. so, assuming you always know the root object of your graph, then this special behavior only needs to exist on these root objects. if any object could be the root of the graph, you would need it on every object. of course, then every object would be independently re-encrypted. this seems like behavor which would be better to handle outside of the objects themselves. unless of course you have some wrapper class whose only purpose is to encrypt the actual data.
    *If read/writeObject methods are correctly implemented in the root class that I would serialize, Are they automatically used to serialize also other classes that I initialize and save into the DataStruct of my root class?* i would say the documentation on the Serializable interface is pretty clear and concise.

  • Question about how to integrate struts web application into Weblogic Portal

    hi, I'm using Weblogic8.1 Portal and workshop to integrate my existing struts web applications. I know that the struts web application can be imported and integrated as a portlet. But I'm not sure how to integrate the corresponding EJB module into portal?
    any help appreciated!!

    should be simple...
    copy all the jpfs and other classes appropriately into a new portal app.
    Create a new Java Page Flow portlet.
    That should be it.
    The major thing to watch for is how your navigation etc change.
    Kunal Mittal

  • Question about unplugging unit

    Hello.  I have an L540 ThinkPad unit.  While it was sitting in hibernate mode, I unplugged the power cord from the unit (not the wall outlet).  I noticed something that looked like a white flash come from the unit when I did this.  This has happened a few times already.  Is this normal, and if not, is it something that could damage the machine? Thanks in advance!

    Hi there.  By pin, are you talking about the number of prongs on the plug?  If so, it's a 3 pin.  I'll check the connection, but I am hoping this doesn't indicate a more serious problem within the unit. The trouble is that this problem is hard to replicate.  What typically happens is that I will leave the laptop in hibernate mode for a while and it will charge, and if I pull the plug out, then I will see the white flash.  It looks like some kind of discharge of electricity.  If I plug it back in and then unplug it again, nothing happens. I want to mention too that recently, I was playing a game that is somewhat graphically intensive.  I noticed the computer was unplugged, so I plugged it in and the system basically froze.  The settings in the game went haywire and I had to go in and reset them all.  I assumed that maybe it decided to switch the refresh rate between 50 and 60 hz when I did that, but it was a very strange occurrence.

  • Question about ABAP OO

    Dear gurus,
    say, we have a class A, which has a constructor  and a protected method A, and in the constructor we call the method A.
    then we built a class B, which inherits from A, and we redefined the method A, and we do nothing to the constructor.
    we expected that  when we instantiate class B, the redefined version of method A is called automatically, but the debug shows that the original version of method A is called.
    do we  need to redefined the constructor of class B in order to call the redefined method?
    thanks and best regards.
    Jun

    Hi,
    I could come up with this solution.... may be this helps you please check and let me know as its working at my end....
    *       CLASS a DEFINITION
    class a definition.
      public section.
        methods : constructor importing value(a) type i, ab.
    endclass.                    "a DEFINITION
    *       CLASS a IMPLEMENTATION
    class a implementation.
      method constructor.
        write 'Super constructor'.
        if a <> 1.
          call method ab.
        endif.
      endmethod.                    "constructor
      method ab.
        write 'super AB'.
      endmethod.                    "ab
    endclass.                    "a IMPLEMENTATION
    *       CLASS b DEFINITION
    class b definition inheriting from a.
      public section.
        methods : constructor, ab REDEFINITION .
    endclass.                    "a DEFINITION
    *       CLASS a IMPLEMENTATION
    class b implementation.
      method constructor.
        call method super->constructor( 1 ).
        write 'Sub constructor'.
        call method ab.
      endmethod.                    "constructor
      method ab.
        write 'Sub AB'.
      endmethod.                    "ab
    endclass.                    "a IMPLEMENTATION
    data : w_a type ref to a,
           w_b type ref to b.
    start-of-selection.
      create object w_b.
    Regards,
    Siddarth

  • Question about typecast to more generic Class

    I have controls refnum and pages refnum and I want to know which way is better:  
    1) let LabVIEW doing the job
    or 2) use "typecast to more generic Class". 
    In both case the VI works properly. 
    Thanks
    Jean-Marc
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp
    Solved!
    Go to Solution.
    Attachments:
    Test LV86.zip ‏153 KB

    Thanks for your reply Ben.
    I need the controls refnum in the visible part of the pane (for the translation english to french and french to english ).
    Jean-Marc
    Jean-Marc
    LV2009 and LV2013
    Free PDF Report with iTextSharp
    Attachments:
    Translation LV86.zip ‏235 KB

  • Question about ABAP Query

    Hi,
    I have a SQ01 query .. based on that query i have to call another query
    ie : when my basic list gets diplayed .. after i click on it a detailed list should be displayed (this again is another SQ01 query)... is this possible through abap Query and if it is where am i supposed to code this
    Thanks a lot in advance

    HI
    GOOD
    GO THROUGH THIS LINK
    http://www.ams.utoronto.ca/Asset353.aspx
    THANKS
    MRUTYUN

  • Question about abap

    I would not write so rigid formula in this transformation.
    In fact, the formula changes often and I would not manage the change in the formula by creating a systematic OT.
    i want  write this formula in a table or infoobject and so I could change my formula in this table or infoObject without using an OT.
    Is that possible?
    best regard
    francoise

    You can have your constants , etc and other logic fields in another infoobject so as to avoid 'Hardcoding' but then you cannot store ABAP code in another table - because the transformation in itself is another program that is generated on activation. If you can find a way around that - you can store your code anywhere.
    For example if your formula is
    A = B/20 and this 20 can change later - you can maintain the value 20 in another infoobject. This example sounds too trivial but could not get a better one - but just wanted to highlight the possibilities...

  • Question about abap/heaplimit

    Hi,
    This is related to NW04 on AIX and Oracle 10.2.
    I want to find out that how often the WP is restarting. It is based on either disp/wp_auto_restart or heaplimit parameter. The help.sap.com link as follows -
    To determine how many work processes are restarted, use the Computing Center Management System (CCMS) (transaction RZ20). Note that the column Err in the Work Process Overview  (transaction SM50) does not refer to work processes that are restarted.
    I could not find it on RZ20 or RZ03.
    Please let me know if anybody has an indea about it.
    I will appreciate your help.
    Thank you.
    Sume

    Hello Sume,
    You will find information in the help page below:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9c/f78b3ba19dfe47e10000000a11402f/frameset.htm
    Please do following steps:
    - Access transaction RZ20
    - Expand the node SAP CCMS Monitor Templates
    - Double-click on Entire System
    - Expand the node <SID>
    - Expand the R/3 Services node
    - Expand the Work process type node that you want. For example: Dialog
    - Expand the <instance name> node
    There you will see the MTE EndedWpDIA.
    Please check the help page for more information about each MTE.
    Best regards,
    Rafael Toshiaki

  • Question about static context when using classes

    hey there.
    i'm pretty new to java an here's my problem:
    public class kreise {
         public static void main (String[] args) {
             //creating the circles
             create a = new create(1,4,3);
             create b = new create(7,2,5);
             System.out.println(a);
             System.out.println(b);
             //diameters...unimportant right now
             getDiameter a_ = new getDiameter(a.radius);
             getDiameter b_ = new getDiameter(b.radius);
             System.out.println(a_);
             System.out.println(b_);
             //moving the circles
             double x = 2;
             double y = 9;
             double z = 3;
             a = create.move();
             System.out.println(a);
    }creating a circle makes use of the class create which looks like this:
    public class create {
        public double k1;
        public double k2;
        public double radius;
        public create(double x,double y,double r) {
            k1 = x;
            k2 = y;
            radius = r;
        public create move() {
            k1 = 1;
            k2 = 1;
            radius = 3;
            return new create (k1,k2,radius);
        public String toString() {
        return "Koordinaten: "+k1+" / "+k2+". Radius: "+radius;
    }now that's all totally fine, but when i try to usw create.move to change the circles coordinates the compiler says that the non-static method move() can't be referenced from a static context. so far i've seen that my main() funktion MUST be static. when declaring the doubles k1, k2, and radius in create() static it works, but then of course when having created the second circle it overwrites the first one.
    i pretty much have the feeling this is very much a standard beginner problem, but searching for the topic never really brought up my problem exactly. thanks in advance!

    You can't access a non-static method from within a static context. So, you have to call move() from outside of the main method. main has to be static because, in short, at least one method has to be static because there haven't been any objects initialized when the program is started. There are more fundamental problems than with just the static context issue.
    I'm confused by your code though. You call create.move(), but this would only be possible if move() was static, and from what I see, it's not. Now that's just one part of it. My second issue is that the logic behind the move() method is very messy. You shouldn't return a newly instantiated object, instead it should just change the fields of the current object. Also as a general rule, instance fields should be private; you have them as public, and this would be problematic because anything can access it.
    Have you heard of getters and setters? That would be what I recommend.
    Now, also, when you are "moving" it, you are basically creating a new circle with completely differently properties; in light of this, I've renamed it change(). Here would be my version of your code:
    public class CircleTester {
        public static void main (String[] args)
             //Bad way to do it, but here's one way around it:
             new CircleTester().moveCircle();
        private void moveCircle()     //really a bad method, but for now, it'll do
            Circle a = new Circle(1,4,3);
            Circle b = new Circle(7,2,5);
            System.out.println(a);
            System.out.println(b);
            //diameters. Don't need to have a new getDiameter class
            double a_ = a.getRadius() * 2;     //Instead of doing * 2 each time, you could have a method that just returns the radius * 2
            double b_ = b.getRadius() * 2;
            System.out.println(a_);
            System.out.println(b_);
            //move the circle
            a.change(2,9,3);
            System.out.println(a);
    public class Circle {
        private double k1;
        private double k2;
        private double radius;
        public Circle(double x,double y,double r)
            k1 = x;
            k2 = y;
            radius = r;
        public void change(int x, int y, int r)
            k1 = x;
            k2 = y;
            radius = r;
        public String toString()
             return "Koordinaten: "+k1+" / "+k2+". Radius: "+radius;
        public double getRadius()
             return radius;
    }On another note, there is already a ellipse class: http://java.sun.com/j2se/1.5.0/docs/api/java/awt/geom/Ellipse2D.html

Maybe you are looking for

  • Production variances run daily?

    Our production accountant has requested variance analysis on a daily basis in order to get up to date information for the factory staff. We are using costing by period with product cost collectors and currently run overhead / WIP / variance calculati

  • Error KI 280 while converting PR in to PO

    Hi Experts , When we create a sales order with an item of item category (TAS)(Third part sales) a purchase requisition is automatically created and these requisitions pick a G/L account which is defined for third party sales We have been using this G

  • Blackberry app world team plz reply

    hi blackberry app world team, merry Christmas! plz reply of this thread, we are suffering with that.... http://supportforums.blackberry.com/t5/BlackBerry-App-World-General/App-World-Web-Plugin-Error-An-er... Thanks & Regards Dinesh

  • XPath for Java

    Hi all, I have an xml and i would like to do some query to the xml. Is there any XPath API that i can use in java ? Currently using 1.4.2 Is there any other recommendations? Thanks

  • Create a Load Text Data page

    Is there a way to create a page to go directly to Utilities > Data Load/Unload > Load > Load Text Data ?