<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Unit Testing against Struts action(Controller in MVC), In-Container or Mock Objects which One Should We Choose?

    This article is focused on which approach we should choose for unit testing against Struts action, I hope it will give you some help when you have question on how to do unit testing against the controller in MVC.

    OK, let's begin!

    In container? Mock objects?

    There are two kinds of testing, one is in-container and the other is do testing with mock objects. Generally speaking, it was considered to be more really and truly unit testing when you do testing with mock objects, especially when you do testing against java source files which should be run in J2EE container, but as our code become complex which contain more layers, the controller(Struts) will have more depends on the other layer which may be EJB service or other business objects, so when you do unit testing against view layer(here is Struts), it will be a huge work for you to construct the mock objects and also it will have more source code changed as you apply mock objects in your source code, the following is a simply description which describe the classic three layers project, and also considerd to be the most common type of web based project.

    e.g. the Struts action class first call the EJB factory to get an EJB service, and then ask this EJB service to do the work according to the business logic and return the value we need, with the value EJB service returned the action class can choose which page to redirect or do some other data processing ,this could be the classic three layers type, maybe the most common type project we used in our project.

    Therefore, it may not be the best choice for every web based project to apply mock objects unit testing. In the case that Struts action class is close tied with your business object, in-container testing may be an alternate choice for you, because it save your time to write mock objects and the workload to apply the mock objects into your source files but supply the same testing resluts.

    In-container testing sounds good, but when you do testing in this style, it first assume that the depended business service classes used in our Struts action must be verified, if the depended service classes have some defect that happen to be met when we run in-container testing, it will take more time to find which cause the error indeed.

    But I think if we have a complete testing procedure, which cover the service layer and the controller, the service layer have already been verified properly, in-container testing is really the best choice for you to use for testing action class. For project in practice, the Struts action is more or less close tied with other layer, it's not realistic to spend more time on writing mock objects or modifying your source code to apply the mock objects. In my opinion, the recommended solution is that you should focus on Struts layer testing, if the Struts action code is close tied with other service layer which I mean is that there may be only one execute() method in every Struts action take charge for the whole business logic, you should use in-container testing, let other unit testing stuff take charge for service layer which may be out of container unit testing against EJB, in this way you can write your test case at your pleasure, forget the depended layers for a while, the container will take care for other layers for you, and also it will save you lots of time for writing mock objects, the container will give you the real objects instead of mock objects.Mock object testing is more often used for the simple Struts action or the case that it could be influenced by the container when you do unit testing against Struts action.

    posted on 2006-07-06 23:05 Find it, try it, experience it 閱讀(154) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    導航

    統計

    公告

    If there is any question you have, please don't hesitate, let me know ASAP, you can find me at kenees@gmail.com or QQ: 9808873, hope to make friends with you ;)

    常用鏈接

    留言簿(1)

    隨筆檔案

    文章檔案

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 日韩一级片免费观看| 99久久精品毛片免费播放| 无码人妻一区二区三区免费看| 亚洲情a成黄在线观看| 无遮挡国产高潮视频免费观看| 免费无遮挡无码视频网站| 亚洲国产日韩a在线播放| 日本免费网站观看| 久久亚洲精品无码av| 精品国产免费观看久久久| 亚洲日韩精品A∨片无码加勒比| 免费看大黄高清网站视频在线| 亚洲精品人成网线在线播放va| 免费观看a级毛片| 精品一区二区三区无码免费直播| 亚洲AV蜜桃永久无码精品| h视频在线免费观看| 久久精品亚洲综合专区| 91香蕉国产线观看免费全集| 亚洲国产电影在线观看| 国产在线国偷精品产拍免费| 亚洲色自偷自拍另类小说| 成人爽a毛片免费| 亚洲制服丝袜在线播放| 日韩免费视频一区| 国产成人无码精品久久久久免费| 亚洲日韩区在线电影| 免费人成视频在线| 亚洲精品视频免费观看| 亚洲美女视频一区| 日本成人在线免费观看| 一个人免费视频在线观看www| 亚洲综合激情另类小说区| 午夜a级成人免费毛片| 成人妇女免费播放久久久| 激情内射亚洲一区二区三区| 日韩精品免费一区二区三区| 男女一边桶一边摸一边脱视频免费 | 无码日韩人妻AV一区免费l| 亚洲性天天干天天摸| 国产精品jizz在线观看免费|