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

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

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

    posts - 156,  comments - 601,  trackbacks - 0

     本文是針對 之前的通過Spring2.5對單元測試的Annotation支持進行TDD開發 進行擴展,增加了Struts Action層的測試實現。

    Action的測試代碼編寫如下:以WalMartAction為例
     1 public class WalMartAction {
     2 
     3     private SuperStore superStore;
     4 
     5     @Override
     6     public String toString() {
     7         return new ToStringBuilder(this).append("superStore", superStore)
     8                 .toString();
     9     }
    10 
    11     /**
    12      * @param superStore the superStore to set
    13      */
    14     public void setSuperStore(SuperStore superStore) {
    15         this.superStore = superStore;
    16     }
    17     
    18     public String list() {
    19         Collection<Commodity> commodities = superStore.getCommodities();
    20         System.out.println(commodities);
    21         
    22         return "SUCCESS";
    23     }
    24     
    25 }

    針對該Action編寫的測試代碼如下:
     1 @RunWith(SpringJUnit4ClassRunner.class)
     2 @ContextConfiguration(locations = {"classpath:/applicationContext-test.xml"})
     3 @TestExecutionListeners({DependencyInjectionTestExecutionListener.class})
     4 public class WalMartActionTest extends AnnotationStrutsSpringTest {
     5     
     6     private WalMartAction testAction;
     7 
     8     @Before
     9     public void setUp() {
    10         testAction = getProxyAction(WalMartAction.class);
    11         Assert.assertNotNull("TestAction should not null", testAction);
    12     }
    13     
    14     @After
    15     public void tearDown() {
    16         testAction = null;
    17     }
    18     
    19     @Test
    20     public void executeTestActionList() {
    21         System.out.println(testAction.list());
    22         
    23     }
    24     
    25 }

    實現比較簡單,只需要注意以下兩點:

    1. 測試類必須繼承 AnnotationStrutsSpringTest. 該代碼在附件中
    2. 通地
    getProxyAction來構建Action類實例

    這樣雖然Action沒有注入到Spring容器,也可以通過 getProxyAction方法,實現Spring容器的屬性依賴注入實現。

    源碼下載: 下載

    Good Luck!
    Yours Matthew!




    posted on 2011-02-27 19:15 x.matthew 閱讀(1943) 評論(2)  編輯  收藏 所屬分類: Spring|Hibernate|Other framework
    主站蜘蛛池模板: 亚洲高清国产拍精品青青草原| 亚洲免费中文字幕| 亚洲国产一区二区三区| 午夜在线a亚洲v天堂网2019| 97在线视频免费播放| 两性色午夜免费视频| 在线观看av永久免费| 国产av天堂亚洲国产av天堂| 日批视频网址免费观看| 久久精品国产亚洲香蕉| 蜜桃AV无码免费看永久| 亚洲AV无码乱码麻豆精品国产| 日韩不卡免费视频| 亚洲国产成人久久综合| 中文字幕免费在线看线人 | 最近2019中文字幕免费看最新 | 成年18网站免费视频网站| 亚洲人成色99999在线观看| 四虎精品亚洲一区二区三区| 国产免费人成视频尤勿视频| 亚洲精品成人片在线观看精品字幕 | 亚洲一区二区成人| 国产又大又粗又长免费视频| 在线综合亚洲欧洲综合网站| 日本一区二区三区日本免费| 亚洲国产夜色在线观看| 国内自产拍自a免费毛片| 亚洲影院在线观看| 青青青国产在线观看免费网站| 亚洲色大成网站WWW国产| 亚洲精品黄色视频在线观看免费资源 | 国产AV无码专区亚洲AV男同| 中文字幕成人免费视频| 亚洲国产日韩精品| 久久亚洲中文字幕精品一区| 久久WWW免费人成一看片| 国产亚洲精品国产福利在线观看| 亚洲欧洲日产国码无码久久99| 欧洲乱码伦视频免费| xxxx日本在线播放免费不卡| 亚洲欧洲精品国产区|