<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)

    隨筆檔案

    文章檔案

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费v片视频在线观看视频| 在线观看亚洲精品国产| 欧洲亚洲综合一区二区三区 | 国产禁女女网站免费看| 一个人晚上在线观看的免费视频| 久久99国产亚洲高清观看首页| 亚洲三级高清免费| 一边摸一边爽一边叫床免费视频| 少妇中文字幕乱码亚洲影视| 国产一卡二卡≡卡四卡免费乱码| a级成人毛片免费视频高清| 7777久久亚洲中文字幕| 亚洲人成网亚洲欧洲无码久久| 猫咪免费人成网站在线观看| 色多多www视频在线观看免费| 亚洲电影免费观看| 国产亚洲成归v人片在线观看| 和日本免费不卡在线v| 中文字幕久无码免费久久| 亚洲制服丝袜一区二区三区| 中国亚洲女人69内射少妇| 四虎成人免费大片在线| 国产一区二区免费| 老司机免费午夜精品视频| 亚洲av无码不卡久久| 久久精品国产亚洲av麻| 午夜亚洲av永久无码精品 | 国产网站免费观看| 亚洲成人免费电影| 免费无码又爽又刺激网站| 亚洲av成人一区二区三区观看在线| 亚洲激情在线视频| 亚洲午夜福利精品无码| 永久黄网站色视频免费直播| 久久免费看黄a级毛片 | 24小时日本电影免费看| 中国内地毛片免费高清| 有码人妻在线免费看片| 亚洲精品无码成人| 国产亚洲国产bv网站在线| 亚洲综合区图片小说区|