<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

     本文是針對(duì) 之前的通過Spring2.5對(duì)單元測(cè)試的Annotation支持進(jìn)行TDD開發(fā) 進(jìn)行擴(kuò)展,增加了Struts Action層的測(cè)試實(shí)現(xiàn)。

    Action的測(cè)試代碼編寫如下:以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 }

    針對(duì)該Action編寫的測(cè)試代碼如下:
     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 }

    實(shí)現(xiàn)比較簡(jiǎn)單,只需要注意以下兩點(diǎn):

    1. 測(cè)試類必須繼承 AnnotationStrutsSpringTest. 該代碼在附件中
    2. 通地
    getProxyAction來構(gòu)建Action類實(shí)例

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

    源碼下載: 下載

    Good Luck!
    Yours Matthew!




    posted on 2011-02-27 19:15 x.matthew 閱讀(1943) 評(píng)論(2)  編輯  收藏 所屬分類: Spring|Hibernate|Other framework
    主站蜘蛛池模板: 狠狠色伊人亚洲综合成人| 免费91麻豆精品国产自产在线观看| 精品国产亚洲一区二区三区| 成人免费无码大片a毛片| 亚洲最大成人网色| 大陆一级毛片免费视频观看i| 国产精品高清免费网站| 亚洲s码欧洲m码吹潮| 亚洲成av人片不卡无码| 亚洲综合伊人久久综合| baoyu122.永久免费视频| 怡红院亚洲红怡院在线观看| 亚洲国产成人久久77| 亚洲AV永久无码精品| 亚洲综合色成在线播放| 国产美女做a免费视频软件| 亚洲AV无码专区国产乱码不卡| 日产亚洲一区二区三区| 国产成人精品日本亚洲专区61| 免费一级毛片在级播放| 国产高清在线精品免费软件| 国产精品高清免费网站| 免费观看四虎精品成人| 日韩精品亚洲专区在线影视| 亚洲av无码专区国产乱码在线观看| 无码少妇一区二区浪潮免费| 国产亚洲美女精品久久久久| 亚洲中文字幕一二三四区| 亚洲高清成人一区二区三区 | 久久精品国产亚洲综合色| 亚洲精品国产日韩无码AV永久免费网| 免费a级毛片无码a∨蜜芽试看| 亚洲一区二区三区免费在线观看| 亚洲成人免费在线| 亚洲国产精品免费视频| 亚洲www在线观看| 久久精品国产亚洲αv忘忧草| 亚洲成av人片在线看片| 在线精品亚洲一区二区三区| 久久久久亚洲爆乳少妇无| 久视频精品免费观看99|