<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>进化的测试 &#187; 集成测试</title>
	<atom:link href="http://magustest.com/blog/tag/%e9%9b%86%e6%88%90%e6%b5%8b%e8%af%95/feed/" rel="self" type="application/rss+xml" />
	<link>http://magustest.com/blog</link>
	<description>关注软件测试，白盒测试，自动化测试，性能测试</description>
	<lastBuildDate>Wed, 02 Jun 2010 16:12:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Linq to Object在测试中的应用</title>
		<link>http://magustest.com/blog/whiteboxtesting/using-linq-to-object-in-testing/</link>
		<comments>http://magustest.com/blog/whiteboxtesting/using-linq-to-object-in-testing/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 03:34:50 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[白盒测试]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[集成测试]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=563</guid>
		<description><![CDATA[.NET Framework 3.5中引入了一个新特性LINQ（集成语言查询），据说.NET Framework 3.5中很多特性都是为LINQ而服务的，例如Lambda表达式的支持，匿名类型，等等……这篇文章会讲述一个把Linq to Object应用于测试的例子。 前一阵子需要测试一个搜索在线会员的功能，如果一个用户是在线的，那么他所能够被搜索到的信息都会作为一条记录，保存在一个表中，主要的字段有5个，也就是根据这5个字段的信息可以查询出用户想要的在线会员。一个简单的方案就是写一个比较复杂的存储过程，然后根据5个输入来查询出不同的结果，不过DBA说在SQL SERVER中进行逻辑运算的性能不是很好，所以开发人员写了12条存储过程，分别对应不同的组合，那么对于我做集成测试来说，我起码要有12个测试方法对应这12条存储过程。同时我还要设计一定数量的测试数据，供我查询测试，而比较要命的是，这些测试数据随着我对这个功能的理解的深入，在不断地增加，结果就是如果我写第一个测试的时候，我准备的数据是30条，OK，测试通过；等我写到第五个测试的时候，测试数据可能有40条了，当我用这40条测试数据重新指向第一个测试的时候，FAILED!!!这让人非常郁闷。所以我想到了能不能用round trip的方法来进行测试。做一个比喻，假如说我想证明WIN7的计算器程序是正确的，那么可以把相同的计算在WIN XP的计算器中跑一遍，如果两者结果一样，那么我可以认为WIN7的计算器程序也是正确的（如果XP的计算器有错怎么办？先别较真，有风险，但很小）。 我的做法就是，准备一些数据，首先用SUT进行查询，然后用LINQ进行查询，如果两者查询结果一致，那么可以认为程序是正确的，否则就是两者之一存在问题。 首先准备一些测试数据，保存为XML文件，第一方便对测试数据进行CRUD，第二可以用XmlSerializer把这些数据转换为对象，方便用LINQ查询。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 &#60; ?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34; ?&#62; &#60;onlinefriends&#62; &#60;friends&#62; &#60;onlinefrienddata&#62; &#60;friendid&#62;1300010000&#60;/friendid&#62; &#60;province&#62;北京市&#60;/province&#62; &#60;city&#62;北京市&#60;/city&#62; &#60;age&#62;18&#60;/age&#62; &#60;gender&#62;2&#60;/gender&#62; [...]


Related posts:<ol><li><a href='http://magustest.com/blog/net/automatic-generate-xml-instance-by-using-xsd/' rel='bookmark' title='Permanent Link: 用XSD自动生成XML对应的.NET实体类'>用XSD自动生成XML对应的.NET实体类</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/data-driven-test-in-unit-test/' rel='bookmark' title='Permanent Link: 在单元测试中应用数据驱动'>在单元测试中应用数据驱动</a></li>
<li><a href='http://magustest.com/blog/softwaretesting/using-httpcontext-in-unittest/' rel='bookmark' title='Permanent Link: 在C#单元测试中使用HttpContext的简单解决办法'>在C#单元测试中使用HttpContext的简单解决办法</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>.NET Framework 3.5中引入了一个新特性<a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx" target="_blank">LINQ</a>（集成语言查询），据说.NET Framework 3.5中很多特性都是为LINQ而服务的，例如<a href="http://en.wikipedia.org/wiki/Lambda" target="_blank">Lambda表达式</a>的支持，<a href="http://msdn.microsoft.com/zh-cn/library/bb397696.aspx" target="_blank">匿名类型</a>，等等……这篇文章会讲述一个把Linq to Object应用于测试的例子。</p>
<p>前一阵子需要测试一个搜索在线会员的功能，如果一个用户是在线的，那么他所能够被搜索到的信息都会作为一条记录，保存在一个表中，主要的字段有5个，也就是根据这5个字段的信息可以查询出用户想要的在线会员。一个简单的方案就是写一个比较复杂的存储过程，然后根据5个输入来查询出不同的结果，不过DBA说在SQL SERVER中进行逻辑运算的性能不是很好，所以开发人员写了12条存储过程，分别对应不同的组合，那么对于我做集成测试来说，我起码要有12个测试方法对应这12条存储过程。同时我还要设计一定数量的测试数据，供我查询测试，而比较要命的是，这些测试数据随着我对这个功能的理解的深入，在不断地增加，结果就是如果我写第一个测试的时候，我准备的数据是30条，OK，测试通过；等我写到第五个测试的时候，测试数据可能有40条了，当我用这40条测试数据重新指向第一个测试的时候，FAILED!!!这让人非常郁闷。所以我想到了能不能用round trip的方法来进行测试。做一个比喻，假如说我想证明WIN7的计算器程序是正确的，那么可以把相同的计算在WIN XP的计算器中跑一遍，如果两者结果一样，那么我可以认为WIN7的计算器程序也是正确的（如果XP的计算器有错怎么办？先别较真，有风险，但很小）。</p>
<p>我的做法就是，准备一些数据，首先用SUT进行查询，然后用LINQ进行查询，如果两者查询结果一致，那么可以认为程序是正确的，否则就是两者之一存在问题。</p>
<p>首先准备一些测试数据，保存为XML文件，第一方便对测试数据进行CRUD，第二可以用XmlSerializer把这些数据转换为对象，方便用LINQ查询。<br />
<span id="more-563"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;">&lt; ?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;onlinefriends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;friends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1300010000<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>北京市<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>北京市<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>18<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1300010002<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>北京市<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>北京市<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>27<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>false<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1300010004<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/friendid<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>广东省<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/province<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>广州市<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/city<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>45<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/age<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/gender<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/hasphoto<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/onlinefrienddata<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/friends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/onlinefriends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>然后需要有一个类，利用XmlSerializer来反序列化这些测试数据</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>XmlRoot<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;OnlineFriends&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OnlineFriends
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> <span style="color: #FF0000;">bool</span> IsEmpty <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> OnlineFriends fs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> OnlineFriends<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">private</span> OnlineFriends<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> OnlineFriends Instance
	<span style="color: #000000;">&#123;</span>
		get
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>fs.<span style="color: #0000FF;">IsEmpty</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				fs.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">return</span> fs<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Deserialize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var serialzer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> XmlSerializer<span style="color: #000000;">&#40;</span><span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>OnlineFriends<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>XmlReader xmlreader <span style="color: #008000;">=</span> XmlReader.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;OnlineFriends.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			fs <span style="color: #008000;">=</span> serialzer.<span style="color: #0000FF;">Deserialize</span><span style="color: #000000;">&#40;</span>xmlreader<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">as</span> OnlineFriends<span style="color: #008000;">;</span>
			fs.<span style="color: #0000FF;">IsEmpty</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> OnlineFriendData
	<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;FriendId&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> FriendId <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Province&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Province <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;City&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> City <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Age&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> Age <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Gender&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">byte</span> Gender <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #000000;">&#91;</span>XmlElement<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;HasPhoto&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
		<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> HasPhoto <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span>XmlArray<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Friends&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #000000;">&#91;</span>XmlArrayItem<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;OnlineFriendData&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0600FF;">public</span> OnlineFriendData<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Friends <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>数据的准备工作就差不多了，看一个简单的测试。首先这个测试方法会重新初始化测试数据，然后查询27岁的在线会员，查询出来的结果保存在ids的INT列表中。OnlineFriends.Instance.Friends对象中保存了所有在线好友的数据，它是一个实现了IEnumerable<t>接口的类，所以可以使用LINQ相关的<a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx" target="_blank">扩展方法</a>。</p>
<p>在OnlineFriends.Instance.Friends.Where(x => x.Age == age)语句中，“x => x.Age == age”是一个应用了Lambda表达式的匿名委托，整个语句的意思就是在OnlineFriends.Instance.Friends这个集合中，找到年龄==age的元素。</p>
<p>不过找到了以后还不行啊，SUT返回的是INT列表，而刚才查到的是OnlineFriendData对象的集合，接下来可以用Select(y => y.FriendId).ToList<int>()对集合做一个投影，只取出FriendId属性，并且转换为INT列表。</p>
<p>最后用CollectionAssert.AreEquivalent()方法对两个INT列表进行比较，看列表是否相等。</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">&#91;</span>TestMethod<span style="color: #000000;">&#93;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> GetOnlineFriendsIdList_Query_Age_LowerUpperDiffOne<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">//重新初始化测试数据</span>
	TestHelp.<span style="color: #0000FF;">InitForSearch</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #FF0000;">int</span> age <span style="color: #008000;">=</span> <span style="color: #FF0000;">27</span><span style="color: #008000;">;</span>
	OnlineFriendQuery query <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> OnlineFriendQuery<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	query.<span style="color: #0000FF;">AgeLowerBound</span> <span style="color: #008000;">=</span> age<span style="color: #008000;">;</span>
	query.<span style="color: #0000FF;">AgeUpperBound</span> <span style="color: #008000;">=</span> age<span style="color: #008000;">;</span>
             <span style="color: #008080; font-style: italic;">//根据条件查询在线会员，在这里就是要查询27岁的会员</span>
	List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> ids <span style="color: #008000;">=</span> FriendListGateway.<span style="color: #0000FF;">FriendListProvider</span>.<span style="color: #0000FF;">GetOnlineFriendsIdList</span><span style="color: #000000;">&#40;</span>query, MyAllPc<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//Two collects are equivalent</span>
	CollectionAssert.<span style="color: #0000FF;">AreEquivalent</span><span style="color: #000000;">&#40;</span>OnlineFriends.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">Friends</span>.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">=&gt;</span> x.<span style="color: #0000FF;">Age</span> <span style="color: #008000;">==</span> age<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Select</span><span style="color: #000000;">&#40;</span>y <span style="color: #008000;">=&gt;</span> y.<span style="color: #0000FF;">FriendId</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #008000;">&lt;/</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, ids<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;">&lt;/</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span></pre></td></tr></table></div>

<p>假如使用我最开始的测试方法（就是先准备测试数据，然后人工统计一下里面有多少个27岁的数据，最后进行比较），我在完成了这一条测试以后，接下来还要小心翼翼地添加测试数据，不能再添加年龄是27岁的数据，要不然就会影响到测试结果。但是应用了LINQ以后，我在后续的测试数据设计中就无需要担心新设计的测试数据会对老的测试造成影响。甚至我还可以用程序生成各种不同的数据，填入数据库，供我测试用。</int></t></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&amp;annotation=.NET%20Framework%203.5%E4%B8%AD%E5%BC%95%E5%85%A5%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%B0%E7%89%B9%E6%80%A7LINQ%EF%BC%88%E9%9B%86%E6%88%90%E8%AF%AD%E8%A8%80%E6%9F%A5%E8%AF%A2%EF%BC%89%EF%BC%8C%E6%8D%AE%E8%AF%B4.NET%20Framework%203.5%E4%B8%AD%E5%BE%88%E5%A4%9A%E7%89%B9%E6%80%A7%E9%83%BD%E6%98%AF%E4%B8%BALINQ%E8%80%8C%E6%9C%8D%E5%8A%A1%E7%9A%84%EF%BC%8C%E4%BE%8B%E5%A6%82Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E6%94%AF%E6%8C%81%EF%BC%8C%E5%8C%BF%E5%90%8D%E7%B1%BB%E5%9E%8B%EF%BC%8C%E7%AD%89%E7%AD%89%E2%80%A6%E2%80%A6%E8%BF%99%E7%AF%87%E6%96%87%E7%AB%A0%E4%BC%9A%E8%AE%B2%E8%BF%B0%E4%B8%80%E4%B8%AA%E6%8A%8ALinq%20to%20Object%E5%BA%94" title="Google Bookmarks"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&amp;bodytext=.NET%20Framework%203.5%E4%B8%AD%E5%BC%95%E5%85%A5%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%B0%E7%89%B9%E6%80%A7LINQ%EF%BC%88%E9%9B%86%E6%88%90%E8%AF%AD%E8%A8%80%E6%9F%A5%E8%AF%A2%EF%BC%89%EF%BC%8C%E6%8D%AE%E8%AF%B4.NET%20Framework%203.5%E4%B8%AD%E5%BE%88%E5%A4%9A%E7%89%B9%E6%80%A7%E9%83%BD%E6%98%AF%E4%B8%BALINQ%E8%80%8C%E6%9C%8D%E5%8A%A1%E7%9A%84%EF%BC%8C%E4%BE%8B%E5%A6%82Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E6%94%AF%E6%8C%81%EF%BC%8C%E5%8C%BF%E5%90%8D%E7%B1%BB%E5%9E%8B%EF%BC%8C%E7%AD%89%E7%AD%89%E2%80%A6%E2%80%A6%E8%BF%99%E7%AF%87%E6%96%87%E7%AB%A0%E4%BC%9A%E8%AE%B2%E8%BF%B0%E4%B8%80%E4%B8%AA%E6%8A%8ALinq%20to%20Object%E5%BA%94" title="Digg"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&amp;notes=.NET%20Framework%203.5%E4%B8%AD%E5%BC%95%E5%85%A5%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%B0%E7%89%B9%E6%80%A7LINQ%EF%BC%88%E9%9B%86%E6%88%90%E8%AF%AD%E8%A8%80%E6%9F%A5%E8%AF%A2%EF%BC%89%EF%BC%8C%E6%8D%AE%E8%AF%B4.NET%20Framework%203.5%E4%B8%AD%E5%BE%88%E5%A4%9A%E7%89%B9%E6%80%A7%E9%83%BD%E6%98%AF%E4%B8%BALINQ%E8%80%8C%E6%9C%8D%E5%8A%A1%E7%9A%84%EF%BC%8C%E4%BE%8B%E5%A6%82Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E6%94%AF%E6%8C%81%EF%BC%8C%E5%8C%BF%E5%90%8D%E7%B1%BB%E5%9E%8B%EF%BC%8C%E7%AD%89%E7%AD%89%E2%80%A6%E2%80%A6%E8%BF%99%E7%AF%87%E6%96%87%E7%AB%A0%E4%BC%9A%E8%AE%B2%E8%BF%B0%E4%B8%80%E4%B8%AA%E6%8A%8ALinq%20to%20Object%E5%BA%94" title="del.icio.us"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;t=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F&amp;title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&amp;body=.NET%20Framework%203.5%E4%B8%AD%E5%BC%95%E5%85%A5%E4%BA%86%E4%B8%80%E4%B8%AA%E6%96%B0%E7%89%B9%E6%80%A7LINQ%EF%BC%88%E9%9B%86%E6%88%90%E8%AF%AD%E8%A8%80%E6%9F%A5%E8%AF%A2%EF%BC%89%EF%BC%8C%E6%8D%AE%E8%AF%B4.NET%20Framework%203.5%E4%B8%AD%E5%BE%88%E5%A4%9A%E7%89%B9%E6%80%A7%E9%83%BD%E6%98%AF%E4%B8%BALINQ%E8%80%8C%E6%9C%8D%E5%8A%A1%E7%9A%84%EF%BC%8C%E4%BE%8B%E5%A6%82Lambda%E8%A1%A8%E8%BE%BE%E5%BC%8F%E7%9A%84%E6%94%AF%E6%8C%81%EF%BC%8C%E5%8C%BF%E5%90%8D%E7%B1%BB%E5%9E%8B%EF%BC%8C%E7%AD%89%E7%AD%89%E2%80%A6%E2%80%A6%E8%BF%99%E7%AF%87%E6%96%87%E7%AB%A0%E4%BC%9A%E8%AE%B2%E8%BF%B0%E4%B8%80%E4%B8%AA%E6%8A%8ALinq%20to%20Object%E5%BA%94" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=Linq%20to%20Object%E5%9C%A8%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BA%94%E7%94%A8%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fusing-linq-to-object-in-testing%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>Related posts:<ol><li><a href='http://magustest.com/blog/net/automatic-generate-xml-instance-by-using-xsd/' rel='bookmark' title='Permanent Link: 用XSD自动生成XML对应的.NET实体类'>用XSD自动生成XML对应的.NET实体类</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/data-driven-test-in-unit-test/' rel='bookmark' title='Permanent Link: 在单元测试中应用数据驱动'>在单元测试中应用数据驱动</a></li>
<li><a href='http://magustest.com/blog/softwaretesting/using-httpcontext-in-unittest/' rel='bookmark' title='Permanent Link: 在C#单元测试中使用HttpContext的简单解决办法'>在C#单元测试中使用HttpContext的简单解决办法</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/whiteboxtesting/using-linq-to-object-in-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>单元测试中的异常处理</title>
		<link>http://magustest.com/blog/whiteboxtesting/exception-handling-in-unit-test/</link>
		<comments>http://magustest.com/blog/whiteboxtesting/exception-handling-in-unit-test/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 02:21:42 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[白盒测试]]></category>
		<category><![CDATA[软件测试]]></category>
		<category><![CDATA[单元测试]]></category>
		<category><![CDATA[自动化测试]]></category>
		<category><![CDATA[集成测试]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=398</guid>
		<description><![CDATA[最近项目不是十分多，所以大部分的学习来自于书本还有同行的博客，淘宝的QA Team博客就是一个很好博客，里面N多淘宝的工程师写，而且更新的非常频繁，质量也很好。翠翠同学以后就要加入淘宝了，以后就能看到他写的博客了。 早上来看到一篇文章，大概讲的是在单元测试中容易用到了Try&#8230;Catch语句而容易出现的一个错误，这里想说一下我对单元测试中异常处理的。记得一个牛人曾经说过（实在想不起来谁也搜不到），大概的意思就是“处理一个问题的最好的办法就是不去处理它”。我不知道当时他讲这句话的具体场景是什么，不过我觉得这句话用在单元测试的异常处理中还是比较合适的。 首先来看看两条关于异常处理的原则 如果无法处理某个异常，那么就不要捕获它 如果捕获到一个异常，那么不要胡乱处理它 单元测试的代码和开发的生产代码，虽然同是程序代码，但是他们存在的意义是不一样的。前者是验证程序的正确性，属于为程序服务的；后者是实现某种功能，属于为客户服务的。然后在看上面的两条异常处理的原则。 作为测试代码，如果捕获到一个异常，其实是无法处理它的。从某种角度来看，测试代码和被测代码是不在一个系统中，AUT所抛出的异常，测试代码无法处理，其实也无需处理。 假如测试代码捕获了一个异常，那么唯一能做的事情就是把这个异常重新包装一下，或者直接重新抛出给单元测试框架，然后由单元测试框架打印到界面上或者是执行结果中。但是其实我们什么都不做（不用Try&#8230;Catch）也能达到这样的效果。 可能会有这样的一些测试用例：在输入某些数据的情况下，该函数会抛出某异常。测试工程师就是要验证有异常的抛出。如果是这样的情况，可以用ExpectedException的Attribute（.NET）来标识出该测试代码必须要抛出该异常，如果没有抛出，该测试就是失败。 所以在单元测试的代码中出现Try&#8230;Catch其实是没有必要的，如果是真的觉得要使用Try&#8230;Catch才能完成某些用例，那么我觉得可以重新设计测试用例，或者测试用例的实现。Try&#8230;Catch增加了测试代码的不确定性，而这样的不确定性会导致诡异的自动化测试脚本的出现。在回归测试的过程中就有可能出现运行10次测试，有2次失败8次成功的情况。 不过在单元测试（集成测试）中Try&#8230;Finally语句的使用还是很有必要的，例如我们会把数据库链接释放的代码放在Finally语句块中，保证测试运行无论成功还是失败，都能释放数据库链接，或者其他昂贵的系统资源。 总结：在单元测试（集成测试等……）中，尽量不要使用Try&#8230;Catch代码块；如果需要释放昂贵或者有限的系统资源、做清理工作，可以把相关的代码放在Finally代码块中。 参考资料： 异常处理 &#8211; MSDN 异常处理原则 理解.NET中的异常 单元测试之新手最容易犯的错误 Share and Enjoy: Related posts:自动化单元测试要点


Related posts:<ol><li><a href='http://magustest.com/blog/whiteboxtesting/unit-test-and-integration-test/' rel='bookmark' title='Permanent Link: 自动化单元测试要点'>自动化单元测试要点</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>最近项目不是十分多，所以大部分的学习来自于书本还有同行的博客，<a href="http://rdc.taobao.com/blog/qa/" target="_blank">淘宝的QA Team博客</a>就是一个很好博客，里面N多淘宝的工程师写，而且更新的非常频繁，质量也很好。翠翠同学以后就要加入淘宝了，以后就能看到他写的博客了。</p>
<p>早上来看到一篇文章，大概讲的是在单元测试中容易用到了Try&#8230;Catch语句而容易出现的一个错误，这里想说一下我对单元测试中异常处理的。记得一个牛人曾经说过（实在想不起来谁也搜不到），大概的意思就是“<strong>处理一个问题的最好的办法就是不去处理它</strong>”。我不知道当时他讲这句话的具体场景是什么，不过我觉得这句话用在单元测试的异常处理中还是比较合适的。</p>
<p>首先来看看两条关于异常处理的原则</p>
<ul>
<li>如果无法处理某个异常，那么就不要捕获它</li>
<li>如果捕获到一个异常，那么不要胡乱处理它</li>
</ul>
<p>单元测试的代码和开发的生产代码，虽然同是程序代码，但是他们存在的意义是不一样的。前者是验证程序的正确性，属于为程序服务的；后者是实现某种功能，属于为客户服务的。然后在看上面的两条异常处理的原则。<br />
<span id="more-398"></span></p>
<ul>
<li> 作为测试代码，如果捕获到一个异常，其实是无法处理它的。从某种角度来看，测试代码和被测代码是不在一个系统中，AUT所抛出的异常，测试代码无法处理，其实也无需处理。</li>
<li>假如测试代码捕获了一个异常，那么唯一能做的事情就是把这个异常重新包装一下，或者直接重新抛出给单元测试框架，然后由单元测试框架打印到界面上或者是执行结果中。但是其实我们什么都不做（不用Try&#8230;Catch）也能达到这样的效果。</li>
</ul>
<p>可能会有这样的一些测试用例：在输入某些数据的情况下，该函数会抛出某异常。测试工程师就是要验证有异常的抛出。如果是这样的情况，可以用ExpectedException的Attribute（.NET）来标识出该测试代码必须要抛出该异常，如果没有抛出，该测试就是失败。</p>
<p>所以在单元测试的代码中出现Try&#8230;Catch其实是没有必要的，如果是真的觉得要使用Try&#8230;Catch才能完成某些用例，那么我觉得可以重新设计测试用例，或者测试用例的实现。Try&#8230;Catch增加了测试代码的不确定性，而这样的不确定性会导致<a href="http://magustest.com/blog/softwaretesting/automationtesting/avoid-flakey-automation-test/" target="_blank">诡异的自动化测试脚本</a>的出现。在回归测试的过程中就有可能出现运行10次测试，有2次失败8次成功的情况。</p>
<p>不过在单元测试（集成测试）中Try&#8230;Finally语句的使用还是很有必要的，例如我们会把数据库链接释放的代码放在Finally语句块中，保证测试运行无论成功还是失败，都能释放数据库链接，或者其他昂贵的系统资源。</p>
<p>总结：在单元测试（集成测试等……）中，尽量不要使用Try&#8230;Catch代码块；如果需要释放昂贵或者有限的系统资源、做清理工作，可以把相关的代码放在Finally代码块中。</p>
<p><strong>参考资料：</strong></p>
<p><a href="http://msdn.microsoft.com/zh-cn/library/ms229005.aspx" target="_blank">异常处理 &#8211; MSDN</a></p>
<p><a href="http://www.blogjava.net/usherlight/archive/2006/10/23/76782.html" target="_blank">异常处理原则</a></p>
<p><a href="http://www.cnblogs.com/anderslly/archive/2007/03/15/675642.html" target="_blank">理解.NET中的异常</a></p>
<p><a href="http://rdc.taobao.com/blog/qa/?p=1317" target="_blank">单元测试之新手最容易犯的错误</a></p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F&amp;t=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F&title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F&title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F&amp;title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F&amp;title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86&amp;body=%E6%9C%80%E8%BF%91%E9%A1%B9%E7%9B%AE%E4%B8%8D%E6%98%AF%E5%8D%81%E5%88%86%E5%A4%9A%EF%BC%8C%E6%89%80%E4%BB%A5%E5%A4%A7%E9%83%A8%E5%88%86%E7%9A%84%E5%AD%A6%E4%B9%A0%E6%9D%A5%E8%87%AA%E4%BA%8E%E4%B9%A6%E6%9C%AC%E8%BF%98%E6%9C%89%E5%90%8C%E8%A1%8C%E7%9A%84%E5%8D%9A%E5%AE%A2%EF%BC%8C%E6%B7%98%E5%AE%9D%E7%9A%84QA%20Team%E5%8D%9A%E5%AE%A2%E5%B0%B1%E6%98%AF%E4%B8%80%E4%B8%AA%E5%BE%88%E5%A5%BD%E5%8D%9A%E5%AE%A2%EF%BC%8C%E9%87%8C%E9%9D%A2N%E5%A4%9A%E6%B7%98%E5%AE%9D%E7%9A%84%E5%B7%A5%E7%A8%8B%E5%B8%88%E5%86%99%EF%BC%8C%E8%80%8C%E4%B8%94%E6%9B%B4%E6%96%B0%E7%9A%84%E9%9D%9E%E5%B8%B8%E9%A2%91%E7%B9%81%EF%BC%8C%E8%B4%A8%E9%87%8F%E4%B9%9F%E5%BE%88%E5%A5%BD%E3%80%82%E7%BF%A0%E7%BF%A0%E5%90%8C%E5%AD%A6%E4%BB%A5%E5%90%8E%E5%B0%B1%E8%A6%81%E5%8A" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E4%B8%AD%E7%9A%84%E5%BC%82%E5%B8%B8%E5%A4%84%E7%90%86%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Fexception-handling-in-unit-test%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>Related posts:<ol><li><a href='http://magustest.com/blog/whiteboxtesting/unit-test-and-integration-test/' rel='bookmark' title='Permanent Link: 自动化单元测试要点'>自动化单元测试要点</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/whiteboxtesting/exception-handling-in-unit-test/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>自动化单元测试要点</title>
		<link>http://magustest.com/blog/whiteboxtesting/unit-test-and-integration-test/</link>
		<comments>http://magustest.com/blog/whiteboxtesting/unit-test-and-integration-test/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 14:13:26 +0000</pubDate>
		<dc:creator>magus</dc:creator>
				<category><![CDATA[白盒测试]]></category>
		<category><![CDATA[自动化测试]]></category>
		<category><![CDATA[软件测试]]></category>
		<category><![CDATA[单元测试]]></category>
		<category><![CDATA[接口测试]]></category>
		<category><![CDATA[集成测试]]></category>

		<guid isPermaLink="false">http://magustest.com/blog/?p=362</guid>
		<description><![CDATA[用单元测试的框架MSTEST，做单元测试，集成测试快1年了，总结一下工作中学到都东西。 单元测试，集成测试有什么用？ 1. 改进产品质量 软件测试，很多时候围绕着两个问题： Verification和Validation，常说的双V。前面的Verification就是Is the software built correctly?。后面的Validation就是Have we built the right software? 单元测试，更多的是Verification。所以有时候经过我单元测试和集成测试以后的功能模块，在交给其他同事做功能测试的时候，依然会有一些BUG，这时候开发可能会埋怨我测试得不够完全，诸如此类。但是其实很多时候，我的关注点是单个方法的功能、行为，没有站到更高的位置来测试这个模块。对于这样的问题，开发和测试应该互相体谅，我本人也会提高自身的水平。希望在单元测试和集成测试中也加入更多关于Validation的思考。 有一个提法叫Tests as Specification，单元测试本身其实就是模拟某个模块的使用者（其他的程序）来进行测试。很多时候我写的测试代码也是其他开发人员的参考，尤其在一些事实上或者只是号称自己是敏捷开发的组织里面，测试代码有可能成为详细设计的替代品，因为有可能根本没有详细设计文档。 单元测试的另一个工作就是发现并且定位BUG。对于BUG的定位和重现，在单元测试代码的编写过程中，每个Assert语句后面都要加上尽可能详细的信息，例如导致这个Assert语句失败的每个参数值，期望结果，实际结果等，这些信息可以帮助开发和测试快速定位问题，减少不必要的DEBUG时间。 2. 降低项目的风险 软件测试，其实是用有限来验证无限的一个过程，很多时候做什么样的测试，做到什么样的程度，很多时候都跟风险有关系。 作为产品的安全网，各种测试在项目中都扮演着重要的角色。例如，中美交互的几十个Web Service接口的回归测试，现在有若干个测试，每天定时做回归测试，因为没人知道在美国的服务器会发生什么事情；对于中国的Web Service，在上线前都会通过回归测试，才部署上线。还有全站的Platform Service接口，每次上线前都需要在做回归测试。软件测试的另一个有趣的结论就是：测试只能证明软件有BUG，但是无论什么样的测试，都不能证明被测软件是没有BUG的。问题出来了，我做完回归测试，都通过了，但是我却不能证明这个软件是没有BUG的。其实每次上线，团队都承担着风险，只不过这样的风险在完成回归测试之后，大家上线的信心增加，风险明显地减小。 什么样的测试才是好的测试？ 1. 容易运行 什么样的单元测试是容易运行？答案很简单，自动化的单元测试就是容易运行的测试。如果一批测试在运行之前每次都需要重装系统然后还要找一大堆需要依赖的软件来装上，最后还要输入奇怪的命令才能运行，那么就不是一个好的测试（本人真的见过这样的测试，囧）。个人认为，配置好的持续集成系统，可以实现很好的自动化测试；如果没有一个完善的CI，那么一个one click的自动化测试运行也是一个较好的选择。 2. 自动检查结果 一句话：没有自动检查结果，再好的自动化也是白搭。 3. 可重复 一句话：只能运行一次的单元测试也是白搭。 4. 独立 其实测试的独立，也有利于实现可重复。刚做单元测试的时候，曾经犯过这样的错误，我在写A测试的时候，给数据库插入了一条记录，然后我在写B测试的时候，就觉得我为什么要在两个测试中分别创建两条数据？直接用上一个测试的数据就可以了。不过结果还好，我很快就发现这样做是有问题。单元测试的独立，就是运行测试的人可以先运行A测试，也可以先运行B测试，也可以单独运行A或者B测试，甚至可以A和B测试同时运行。 5. 简单 有时候，测试的代码写的有点复杂，嵌套的语句有点多，可能有些人会觉得写出复杂的单元测试代码才能体现自己的水平，但是，我觉得对于单元测试代码来说，应该越简单越好。最好就是顺序执行下来了，不要有什么分支。因为测试代码本身就是也是代码，那么怎么去验证测试代码写的正确呢？答案可能是再写一个测试代码去验证第一个测试代码。这样就会有死循环了。一个简单的假设就是，如果测试代码足够简单，那么就可以认为测试代码是正确的，无需其他代码对之进行测试。 6. 专注 一个测试应该只测试一个点。如果在一个测试里面验证多个测试点，看起来是比较高效的一种做法，但是当测试中有Assert语句抛出异常的时候，很有可能需要花大量的时间才能找到真正错误的代码，这样不利于实现前面提及到的“定位BUG”。 7. 注释 注释其实就是把代码抽取成可阅读的测试用例，如果别人看自己的程序，可以快速理解测试代码；同时注释还能唤醒自己沉睡的记忆和当时的测试思路。 国内做单元测试的测试工程师少，做集成测试、接口测试的也不多，埋头做事,别忘抬头看路。时常总结，提高自我。 Share and Enjoy: Related [...]


Related posts:<ol><li><a href='http://magustest.com/blog/readingdaily/software-testing-note-part-three/' rel='bookmark' title='Permanent Link: 《Software Testing》第三章 &#8211; 软件测试'>《Software Testing》第三章 &#8211; 软件测试</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/exception-handling-in-unit-test/' rel='bookmark' title='Permanent Link: 单元测试中的异常处理'>单元测试中的异常处理</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>用单元测试的框架MSTEST，做单元测试，集成测试快1年了，总结一下工作中学到都东西。</p>
<p><span style="color: #ff0000;"><strong>单元测试，集成测试有什么用？</strong></span></p>
<p><strong>1. 改进产品质量</strong></p>
<p>软件测试，很多时候围绕着两个问题：</p>
<p>Verification和Validation，常说的双V。前面的Verification就是Is the software built correctly?。后面的Validation就是Have we built the right software?</p>
<p>单元测试，更多的是Verification。所以有时候经过我单元测试和集成测试以后的功能模块，在交给其他同事做功能测试的时候，依然会有一些BUG，这时候开发可能会埋怨我测试得不够完全，诸如此类。但是其实很多时候，我的关注点是单个方法的功能、行为，没有站到更高的位置来测试这个模块。对于这样的问题，开发和测试应该互相体谅，我本人也会提高自身的水平。希望在单元测试和集成测试中也加入更多关于Validation的思考。<br />
<span id="more-362"></span><br />
有一个提法叫Tests as Specification，单元测试本身其实就是模拟某个模块的使用者（其他的程序）来进行测试。很多时候我写的测试代码也是其他开发人员的参考，尤其在一些事实上或者只是号称自己是敏捷开发的组织里面，测试代码有可能成为详细设计的替代品，因为有可能根本没有详细设计文档。</p>
<p>单元测试的另一个工作就是发现并且定位BUG。对于BUG的定位和重现，在单元测试代码的编写过程中，每个Assert语句后面都要加上尽可能详细的信息，例如导致这个Assert语句失败的每个参数值，期望结果，实际结果等，这些信息可以帮助开发和测试快速定位问题，减少不必要的DEBUG时间。</p>
<p><strong>2. 降低项目的风险</strong></p>
<p>软件测试，其实是用有限来验证无限的一个过程，很多时候做什么样的测试，做到什么样的程度，很多时候都跟风险有关系。</p>
<p>作为产品的安全网，各种测试在项目中都扮演着重要的角色。例如，中美交互的几十个Web Service接口的回归测试，现在有若干个测试，每天定时做回归测试，因为没人知道在美国的服务器会发生什么事情；对于中国的Web Service，在上线前都会通过回归测试，才部署上线。还有全站的Platform Service接口，每次上线前都需要在做回归测试。软件测试的另一个有趣的结论就是：测试只能证明软件有BUG，但是无论什么样的测试，都不能证明被测软件是没有BUG的。问题出来了，我做完回归测试，都通过了，但是我却不能证明这个软件是没有BUG的。其实每次上线，团队都承担着风险，只不过这样的风险在完成回归测试之后，大家上线的信心增加，风险明显地减小。</p>
<p><span style="color: #ff0000;"><strong>什么样的测试才是好的测试？</strong></span></p>
<p><strong>1. 容易运行</strong></p>
<p>什么样的单元测试是容易运行？答案很简单，自动化的单元测试就是容易运行的测试。如果一批测试在运行之前每次都需要重装系统然后还要找一大堆需要依赖的软件来装上，最后还要输入奇怪的命令才能运行，那么就不是一个好的测试（本人真的见过这样的测试，囧）。个人认为，配置好的持续集成系统，可以实现很好的自动化测试；如果没有一个完善的CI，那么一个one click的自动化测试运行也是一个较好的选择。</p>
<p><strong>2. 自动检查结果</strong></p>
<p>一句话：没有自动检查结果，再好的自动化也是白搭。</p>
<p><strong>3. 可重复</strong></p>
<p>一句话：只能运行一次的单元测试也是白搭。</p>
<p><strong>4. 独立</strong></p>
<p>其实测试的独立，也有利于实现可重复。刚做单元测试的时候，曾经犯过这样的错误，我在写A测试的时候，给数据库插入了一条记录，然后我在写B测试的时候，就觉得我为什么要在两个测试中分别创建两条数据？直接用上一个测试的数据就可以了。不过结果还好，我很快就发现这样做是有问题。单元测试的独立，就是运行测试的人可以先运行A测试，也可以先运行B测试，也可以单独运行A或者B测试，甚至可以A和B测试同时运行。</p>
<p><strong>5. 简单</strong></p>
<p>有时候，测试的代码写的有点复杂，嵌套的语句有点多，可能有些人会觉得写出复杂的单元测试代码才能体现自己的水平，但是，我觉得对于单元测试代码来说，应该越简单越好。最好就是顺序执行下来了，不要有什么分支。因为测试代码本身就是也是代码，那么怎么去验证测试代码写的正确呢？答案可能是再写一个测试代码去验证第一个测试代码。这样就会有死循环了。一个简单的假设就是，如果测试代码足够简单，那么就可以认为测试代码是正确的，无需其他代码对之进行测试。</p>
<p><strong>6. 专注</strong></p>
<p>一个测试应该只测试一个点。如果在一个测试里面验证多个测试点，看起来是比较高效的一种做法，但是当测试中有Assert语句抛出异常的时候，很有可能需要花大量的时间才能找到真正错误的代码，这样不利于实现前面提及到的“定位BUG”。</p>
<p><strong>7. 注释</strong></p>
<p>注释其实就是把代码抽取成可阅读的测试用例，如果别人看自己的程序，可以快速理解测试代码；同时注释还能唤醒自己沉睡的记忆和当时的测试思路。</p>
<p>国内做单元测试的测试工程师少，做集成测试、接口测试的也不多，埋头做事,别忘抬头看路。时常总结，提高自我。</p>



Share and Enjoy:


	<a rel="nofollow"  target="_blank" href="http://magustest.com/blog/feed/" title="RSS"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://digg.com/submit?phase=2&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&amp;bodytext=%E7%94%A8%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E7%9A%84%E6%A1%86%E6%9E%B6MSTEST%EF%BC%8C%E5%81%9A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E5%BF%AB1%E5%B9%B4%E4%BA%86%EF%BC%8C%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8B%E5%B7%A5%E4%BD%9C%E4%B8%AD%E5%AD%A6%E5%88%B0%E9%83%BD%E4%B8%9C%E8%A5%BF%E3%80%82%0A%0A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E6%9C%89%E4%BB%80%E4%B9%88%E7%94%A8%EF%BC%9F%0A%0A1.%20%E6%94%B9%E8%BF%9B%E4%BA%A7%E5%93%81%E8%B4%A8%E9%87%8F%0A%0A%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%EF%BC%8C%E5%BE%88%E5%A4%9A%E6%97%B6%E5%80%99%E5%9B%B4%E7%BB%95%E7%9D%80%E4%B8%A4%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9A%0A%0AVerification%E5" title="Digg"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/digg.png" title="Digg" alt="Digg" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://delicious.com/post?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&amp;notes=%E7%94%A8%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E7%9A%84%E6%A1%86%E6%9E%B6MSTEST%EF%BC%8C%E5%81%9A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E5%BF%AB1%E5%B9%B4%E4%BA%86%EF%BC%8C%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8B%E5%B7%A5%E4%BD%9C%E4%B8%AD%E5%AD%A6%E5%88%B0%E9%83%BD%E4%B8%9C%E8%A5%BF%E3%80%82%0A%0A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E6%9C%89%E4%BB%80%E4%B9%88%E7%94%A8%EF%BC%9F%0A%0A1.%20%E6%94%B9%E8%BF%9B%E4%BA%A7%E5%93%81%E8%B4%A8%E9%87%8F%0A%0A%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%EF%BC%8C%E5%BE%88%E5%A4%9A%E6%97%B6%E5%80%99%E5%9B%B4%E7%BB%95%E7%9D%80%E4%B8%A4%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9A%0A%0AVerification%E5" title="del.icio.us"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.facebook.com/share.php?u=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&amp;t=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9" title="Facebook"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9" title="豆瓣"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban.png" title="豆瓣" alt="豆瓣" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.douban.com/recommend/?url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&n=1" title="豆瓣九点"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/douban9.png" title="豆瓣九点" alt="豆瓣九点" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://www.friendfeed.com/share?title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&amp;link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F" title="FriendFeed"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/friendfeed.png" title="FriendFeed" alt="FriendFeed" class="sociable-hovers" /></a>
	<img src="http://magustest.com/blog/wp-content/plugins/sociable/images/linkedin.png" title="LinkedIn" alt="LinkedIn" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;url=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9" title="Live"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/live.png" title="Live" alt="Live" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://ping.fm/ref/?link=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F&amp;title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&amp;body=%E7%94%A8%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E7%9A%84%E6%A1%86%E6%9E%B6MSTEST%EF%BC%8C%E5%81%9A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E5%BF%AB1%E5%B9%B4%E4%BA%86%EF%BC%8C%E6%80%BB%E7%BB%93%E4%B8%80%E4%B8%8B%E5%B7%A5%E4%BD%9C%E4%B8%AD%E5%AD%A6%E5%88%B0%E9%83%BD%E4%B8%9C%E8%A5%BF%E3%80%82%0A%0A%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%EF%BC%8C%E9%9B%86%E6%88%90%E6%B5%8B%E8%AF%95%E6%9C%89%E4%BB%80%E4%B9%88%E7%94%A8%EF%BC%9F%0A%0A1.%20%E6%94%B9%E8%BF%9B%E4%BA%A7%E5%93%81%E8%B4%A8%E9%87%8F%0A%0A%E8%BD%AF%E4%BB%B6%E6%B5%8B%E8%AF%95%EF%BC%8C%E5%BE%88%E5%A4%9A%E6%97%B6%E5%80%99%E5%9B%B4%E7%BB%95%E7%9D%80%E4%B8%A4%E4%B8%AA%E9%97%AE%E9%A2%98%EF%BC%9A%0A%0AVerification%E5" title="Ping.fm"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/ping.png" title="Ping.fm" alt="Ping.fm" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://shuqian.qq.com/post?jumpback=1&title=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9&uri=http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F" title="QQ书签"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/qq.png" title="QQ书签" alt="QQ书签" class="sociable-hovers" /></a>
	<a rel="nofollow"  target="_blank" href="http://twitter.com/home?status=%E8%87%AA%E5%8A%A8%E5%8C%96%E5%8D%95%E5%85%83%E6%B5%8B%E8%AF%95%E8%A6%81%E7%82%B9%20-%20http%3A%2F%2Fmagustest.com%2Fblog%2Fwhiteboxtesting%2Funit-test-and-integration-test%2F" title="Twitter"><img src="http://magustest.com/blog/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a>


<br/><br/>

<p>Related posts:<ol><li><a href='http://magustest.com/blog/readingdaily/software-testing-note-part-three/' rel='bookmark' title='Permanent Link: 《Software Testing》第三章 &#8211; 软件测试'>《Software Testing》第三章 &#8211; 软件测试</a></li>
<li><a href='http://magustest.com/blog/whiteboxtesting/exception-handling-in-unit-test/' rel='bookmark' title='Permanent Link: 单元测试中的异常处理'>单元测试中的异常处理</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://magustest.com/blog/whiteboxtesting/unit-test-and-integration-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
