• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • StrutsTest使用

    發表于:2009-04-15來源:作者:點擊數: 標簽:StrutsTest
    Struts是目前在web 開發 中廣泛使用的幾個框架之一,而StrutsTest正是專門負責 測試 strut應用程序的Mock 測試框架 。 使用目的 StrtusTest是 junit 的擴展,使用它,不需要啟動servlet容器就可以方便的測試struts應用程序(容器外測試)。它也是屬于使用Mock
    Struts是目前在web開發中廣泛使用的幾個框架之一,而StrutsTest正是專門負責測試strut應用程序的Mock測試框架。
    使用目的
           StrtusTest是junit的擴展,使用它,不需要啟動servlet容器就可以方便的測試struts應用程序(容器外測試)。它也是屬于使用Mock對象測試,但是與EasyMock不同的是,EasyMock是提供了創建Mock對象的API,而StrutsTest則是專門負責測試Struts應用程序的Mock對象測試框架。除了容器外測試,StrutsTest也可以很方便的用容器內的測試。

           當前的版本是StrutsTest2.1.0,在這個版本中不支持Struts1.0。如果需要測試struts1.0的應用程序,對應的版本是StrutsTest2.0??梢詮膆ttp://sourceforge.net/projects/strutstestcase/下載。

    用法
    1.       基本步驟:

    -          書寫struts action。

    -          確定需要進行測試的方式:Mock對象則選用MockStrutsTestCase作為基類;Cactus方式則選用CactusStrutsTestCase;這兩種方式以下的步驟都是一樣的。

    -          使用setUp和tearDown進行初始化,明確這兩個函數的第一句話是調用super的方法。

    -          設置要測試的struts action的路徑,方便strutstest能找到web.xml和struts相關的配置文檔。

    -          設置action在strtus-config.xml中對應的path名稱。

    -          設置action需要使用的各個參數值到request對象中,包括action所使用的formbean的值。

    -          執行action。

    -          驗證action的返回路徑是否正確,即forward的名字。

    -          驗證action相關的其余部分。

    2.       使用例子(采用Mock方式):

    public class DeparmentDBActionTest extends MockStrutsTestCase {

        public DeparmentDBActionTest(String arg0) {

            super(arg0);

        }

    public void setUp(){

            super.setUp();

    //指明web應用的根

            File contextFile = new File("D:\\Projects\\fog\\implement\\web");

            setContextDirectory(contextFile);

        }

        protected void tearDown() throws Exception {

            super.tearDown();

        }

        public void testDoAdd() {

            //設置action的path

            setRequestPathInfo("/dpEdit");

          

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>