﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-VIRGIN FOREST OF JAVA-文章分类-Test</title><link>http://www.blogjava.net/RR00/category/13903.html</link><description>不要埋头苦干，要学习，学习，再学习。。。。。
&lt;br&gt;
powered  by &lt;font color='orange'&gt;R.Zeus&lt;/font&gt;</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 03:21:28 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 03:21:28 GMT</pubDate><ttl>60</ttl><item><title>mock </title><link>http://www.blogjava.net/RR00/articles/61822.html</link><dc:creator>R.Zeus</dc:creator><author>R.Zeus</author><pubDate>Fri, 04 Aug 2006 10:56:00 GMT</pubDate><guid>http://www.blogjava.net/RR00/articles/61822.html</guid><wfw:comment>http://www.blogjava.net/RR00/comments/61822.html</wfw:comment><comments>http://www.blogjava.net/RR00/articles/61822.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/RR00/comments/commentRss/61822.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/RR00/services/trackbacks/61822.html</trackback:ping><description><![CDATA[mock是个模拟测试的东西，她创造的东西都是假的，在数据库测试，网络测试中可以 用的很爽！<br /><br />public class MockPrototypeTestCase extends org.jmock.MockObjectTestCase {<br />    Mock accountService = null;<br /><br />    MockPrototype mo = new MockPrototype();<br />    protected void setUp() throws Exception {<br />        super.setUp();<br />        accountService = new Mock(AccountService.class);<br /><font style="BACKGROUND-COLOR: #ffc0cb" color="#0000ff">//在MockPrototype 要用到AccountService.class，所以这里创建了一个，不过这个不是真实的，是模拟的<br /></font>        mo.setAccountService((AccountService) accountService.proxy());<br />    }<br />    protected void tearDown() throws Exception {<br />        super.tearDown();<br />        mo = null;<br />    }<br />    public void testloginProcess() {<br />        Account a = new Account();<br />        a.setLoginId("aa");<br />        a.setPassword(StringUtil.encodePassword("bb", Constants.PASSWORD_ENCODING_TYPE));<br /><font style="BACKGROUND-COLOR: #ffc0cb" color="#0000ff">//这里模拟了      getAccount，即getAccount("aa"),返回a；在mock中没有真实的东西，都是模拟的！</font><br />  accountService.expects(atLeastOnce()) <font style="BACKGROUND-COLOR: #ffc0cb" color="#0000ff">//注意 atLeastOnce()这个参数，这个指定使用次数，如果是<br /></font>                .method("getAccount")           <font style="BACKGROUND-COLOR: #ffc0cb" color="#000080"> <strong> //atLeastOnce,则这个method中则至少使用一次，否则会报错！</strong></font><br />                .with(eq("aa"))                     <font style="BACKGROUND-COLOR: #ffc0cb" color="#0000ff"> //总之，按照定义的函数调用，同时必须遵守规定，如次数！</font><br />                .will(returnValue(a));            <font style="BACKGROUND-COLOR: #ffc0cb" color="#0000ff">//在mo的loginProcess()中，会用到这些方法<br /></font>        accountService.expects(atLeastOnce())<br />                .method("getAccount")<br />                .with(eq("cc"))<br />                .will(returnValue(null));<br />        mo.loginProcess("aa","bb");<br />        try {<br />            mo.loginProcess("cc","bb");<br />        } catch (FrameworkdemoServiceException e) {<br />            assertEquals(e.getMessage(),"null.lll");  //To change body of catch statement use File | Settings | File Templates.<br />        }<br />    }<br />}<img src ="http://www.blogjava.net/RR00/aggbug/61822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/RR00/" target="_blank">R.Zeus</a> 2006-08-04 18:56 <a href="http://www.blogjava.net/RR00/articles/61822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>