<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
    主站蜘蛛池模板: 国产成人精品亚洲一区| 久久精品国产亚洲网站| 99亚洲精品卡2卡三卡4卡2卡| 国产精品深夜福利免费观看| 国产免费福利体检区久久| 亚洲人成在线观看| 夭天干天天做天天免费看| 国产精品美女免费视频观看| 91亚洲国产在人线播放午夜| 日韩成人免费在线| a级毛片视频免费观看| 亚洲人成综合在线播放| 亚洲精品国产精品国自产观看 | 亚洲国产精品无码专区影院| 99久久国产免费中文无字幕| 亚洲精华国产精华精华液好用| 中文字幕亚洲综合久久男男| 91精品国产免费久久久久久青草 | 97视频免费在线| 青青青视频免费观看| 亚洲精品不卡视频| 亚洲情侣偷拍精品| 色婷婷综合缴情综免费观看| 亚洲欧洲日韩不卡| 又爽又黄无遮挡高清免费视频| 午夜不卡久久精品无码免费| 亚洲AV无码一区二区大桥未久| 亚洲福利视频一区| 亚洲第一黄片大全| 曰批全过程免费视频在线观看| 一级女人18片毛片免费视频| 亚洲国产成人精品激情| 好看的亚洲黄色经典| 国产免费观看a大片的网站| 久久www免费人成看片| 精品97国产免费人成视频| 亚洲性线免费观看视频成熟| 亚洲AV无码一区二区乱孑伦AS| 凹凸精品视频分类国产品免费| 好男人www免费高清视频在线| 无码av免费一区二区三区试看|