<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Valeriu Caraulean &#187; Testing</title>
	<atom:link href="http://blog.caraulean.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caraulean.com</link>
	<description>Keep it simple. It will work...</description>
	<lastBuildDate>Fri, 10 Feb 2012 04:38:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.caraulean.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Valeriu Caraulean &#187; Testing</title>
		<link>http://blog.caraulean.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.caraulean.com/osd.xml" title="Valeriu Caraulean" />
	<atom:link rel='hub' href='http://blog.caraulean.com/?pushpress=hub'/>
		<item>
		<title>Cultural differences&#8230;</title>
		<link>http://blog.caraulean.com/2011/09/21/cultural-differences/</link>
		<comments>http://blog.caraulean.com/2011/09/21/cultural-differences/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 16:13:10 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">https://varely.wordpress.com/2011/09/21/cultural-differences/</guid>
		<description><![CDATA[Today I’ve been helping a coworker to bootstrap new project. Nothing fancy: ASP.NET site hosting WCF services, few POCOs and Entity Framework in Code First mode to rule persist them all. Interesting moment came when he wanted to see if his service actually works. He quickly created another project (Windows Forms) to try connect to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=328&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Today I’ve been helping a coworker to bootstrap new project. Nothing fancy: ASP.NET site hosting WCF services, few POCOs and Entity Framework in Code First mode to <strike>rule</strike> persist them all. </p>
<p>Interesting moment came when he wanted to see if his service actually works. He quickly created another project (Windows Forms) to try connect to newly created service. When I’ve seen that I’ve suggested that a unit test project would be easier and more useful, he preferred to go his route and added buttons, large text block and some plumbing code to take service’s response to the screen.</p>
<p>I’m not blaming here (as he is rather new to .NET platform), but his approach has few disadvantages versus verifying a service using unit tests:</p>
<ul>
<li>it’s slower to create a minimally meaningful solution: a crappy screen with a button “connect” and large text box to see results? I’d prefer a test with an assertion and may be some console output
<li>it’s slower to analyze results: you have to scan the screen to see/analyze replies. I’d prefer that a test assertion would take care of that.
<li>it’s error prone: you have to rely on human input to test it. I’d prefer an automated approach.
<li>it’s not repeatable nor scalable: what if you have second service? 10 methods in service?. I’d create new test fixture and refactor existing code, not UI.
<li>…</li>
</ul>
<p>… lot’s of things that are wrong with this approach. </p>
<p>Even if it’s a short living spike, new project, new feature – whatever needs a proof of code in working state – <strong>I’d prefer to write a test for it</strong>. And I’m not talking here about rigorous Test-Driven-Development approach. It’s more like <strong>acceptance testing at service or component boundaries</strong>, only to be sure that it works as expected. And creating an UI just to see that a service works – it sounds wrong to me. But those are “cultural differences”, I think…</p>
<p>PS: By “cultural differences” I mean past experience, habits, education, professional environment and so on&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=328&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2011/09/21/cultural-differences/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate&#8217;s niceties: hbm2ddl auto mode in unit tests</title>
		<link>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/</link>
		<comments>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 17:33:17 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
				<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/</guid>
		<description><![CDATA[Very often you&#8217;re going over a description of some function or new feature and just notice in your mind, &#8220;nice feature&#8221; without seeing a real application for it. Later, you&#8217;re coming with scenario where the trick you&#8217;ve read days ago will fit perfectly. That was the case when I&#8217;ve seen earlier in Tuna Toksoz&#8216;s weblog [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=40&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Very often you&#8217;re going over a description of some function or new feature and just notice in your mind, &#8220;nice feature&#8221; without seeing a real application for it. Later, you&#8217;re coming with scenario where the trick you&#8217;ve read days ago will fit perfectly.</p>
<p>That was the case when I&#8217;ve seen earlier in <a href="http://www.tunatoksoz.com/">Tuna Toksoz</a>&#8216;s weblog a <a href="http://www.tunatoksoz.com/post/NHibernate-hbm2ddl.aspx">description of &#8220;hbm2ddl.auto&#8221; property</a>. Few days ago, I&#8217;ve put it to work in a way that makes me feel better. By the way, the particular reason that made me happy was that I&#8217;ve deleted a lot of repetitive code from our code base.</p>
<h4>How you can use hbm2ddl.auto property in unit tests</h4>
<p>Our integration tests are run over a real database. For each test we&#8217;re re-creating the database, so that each test will be ran in separation and without interfering with results of previous tests. Also, things are a bit complicated since we&#8217;re working with few databases at the same time, each with his own schema. Before, each test had to use SchemaExport class that exported the database schema built from NHibernate configuration on the way deleting your old database/schema/data. So, each integration test class had same method to call. Redundant and repetitive. Yes, you can make a base class that will do that, but you have to inherit then all tests from that class.</p>
<p><strong>How it works now:</strong> in session configuration (usually in app.config for integration test project) you put:</p>
<blockquote><p>&lt;property name=&#8221;hbm2ddl.auto&#8221;&gt;create&lt;/property&gt;</p>
</blockquote>
<p>&#8230; and you&#8217;re set. Each time your code will build a new SessionFactory, NHibernate will call:</p>
<blockquote><p>new SchemaExport(cfg).Create(false, true);</p>
</blockquote>
<p>This way, before the SessionFactory will be built, your database will be refreshed with a new schema and tests will run in a clean database.</p>
<p>One line of code instead of tens or hundreds. Isn&#8217;t that a good trick?!</p>
<p>&nbsp;</p>
<p>A word of warning &#8211; don&#8217;t let this code escape to your production code. It may be dangerous&#8230; But, you know that, we&#8217;re running with scissors&#8230;</p>
<p><a href="http://altdotnet.org/"><img height="180" alt="RWS2-Big" src="http://varely.files.wordpress.com/2008/12/rws2-big.png?w=468&#038;h=180" width="468"></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=40&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>

		<media:content url="http://varely.files.wordpress.com/2008/12/rws2-big.png" medium="image">
			<media:title type="html">RWS2-Big</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit tests with Automatic Transaction Management</title>
		<link>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/</link>
		<comments>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 16:18:43 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
				<category><![CDATA[Castle]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/10/03/unit-tests-with-automatic-transaction-management/</guid>
		<description><![CDATA[In our projects we&#8217;re using Castle&#8217;s Automatic Transaction Management facility (ATM). This facility allows to declaratively define transaction boundaries: by marking a method by a specific attribute the call to this method will be wrapped in a transaction, so that a transaction will be opened before calling the method and committed right after finishing method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=31&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In our projects we&#8217;re using Castle&#8217;s Automatic Transaction Management facility (ATM). This facility allows to declaratively define transaction boundaries: by marking a method by a specific attribute the call to this method will be wrapped in a transaction, so that a transaction will be opened before calling the method and committed right after finishing method execution.</p>
<p>In code, it looks like this:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:486px;border-bottom:#cecece 1px solid;height:162px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: [Transactional]
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  2: <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Foo
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  3: {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  4:     [Transaction]
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  5:     <span style="color:#0000ff;">public</span> virtual void Bar()
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  6:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  7:         // <span style="color:#0000ff;">Do</span> something <span style="color:#0000ff;">in</span> a transaction
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  8:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  9: }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 10: </pre>
</pre>
<p>Let&#8217;s suppose that later, we want to test this code. Say, we want to verify that code in Foo.Bar() method is executed in a transaction. Moreover, we want to assure that the marking attributes will not be deleted accidentally.</p>
<p>We can test that within two aspects. First &#8211; an integration test: a real application part will be spawned and a call will be performed. After, we should verify that changes was committed by transaction. It takes time to run such a test (integration test usually runs slower) and effort to write &amp; verify such a test. Second way to test that &#8211; is to check presence or required attributes. This will be a fast unit test that will just check that attribute is still applied to a method.</p>
<p>Those methods complements each other. Ideally, it should be both written.</p>
<p>Let&#8217;s see how we can verify that attributes required by ATM are applied to required methods.</p>
<p>First, we&#8217;ve defined the API that we want to use to do our check:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:468px;border-bottom:#cecece 1px solid;height:64px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: CustomAssertions.ShouldUseATM&lt;Foo&gt;(foo =&gt; foo.Bar());</pre>
</pre>
<p>Yes, you see it right, we want to make it type save, refactor-able and nice looking.</p>
<p>This helper class should verify next assumptions, all required by ATM:</p>
<ul>
<li>Tested class should be marked with TransactionalAttribute;
<li>Method should be marked by TransactionAttribute;
<li>Method should be virtual.</li>
</ul>
<p>Solution we came to this problem is the next class:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:495px;border-bottom:#cecece 1px solid;height:636px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: <span style="color:#0000ff;">public</span> static partial <span style="color:#0000ff;">class</span> CustomAssertions
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  2: {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  3:     <span style="color:#0000ff;">public</span> static void ShouldUseATM&lt;T&gt;(Expression&lt;Action&lt;T&gt;&gt; methodExpression) where T : <span style="color:#0000ff;">class</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  4:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  5:         ThrowIfTypeNotMarkedAsTransactional(typeof (T));
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  6:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  7:         var methodInfo = ((MethodCallExpression) methodExpression.Body).Method;
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  8:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  9:         ThrowIfMethodIsNotMarkedWithTransactionAttribute(methodInfo);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 10:         ThrowIfMethodMarkedWithTransactionAttributeIsVirtual(methodInfo);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 11:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 12:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 13:     <span style="color:#0000ff;">private</span> static void ThrowIfTypeNotMarkedAsTransactional(Type classType)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 14:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 15:         object[] foundAttributes = classType.GetCustomAttributes(typeof (TransactionalAttribute), false);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 16:         <span style="color:#0000ff;">if</span> (foundAttributes.Length == 0)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 17:             Assert.Fail("<span style="color:#8b0000;">The type '{0}' is not marked with [Transactional] attribute</span>", classType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 18:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 19:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 20:     <span style="color:#0000ff;">private</span> static void ThrowIfMethodIsNotMarkedWithTransactionAttribute(MethodInfo info)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 21:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 22:         var found = info.GetCustomAttributes(typeof (TransactionAttribute), false);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 23:         <span style="color:#0000ff;">if</span> (found.Length == 0)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 24:             Assert.Fail("<span style="color:#8b0000;">Method '{0}' from '{1}' type is not marked with [Transaction] attribute</span>",
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 25:                         info.Name,
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 26:                         info.DeclaringType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 27:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 28:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 29:     <span style="color:#0000ff;">private</span> static void ThrowIfMethodMarkedWithTransactionAttributeIsVirtual(MethodBase methodInfo)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 30:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 31:         <span style="color:#0000ff;">if</span> (methodInfo.IsVirtual &amp;&amp; !methodInfo.IsFinal)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 32:             return;
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 33:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 34:         Assert.Fail("<span style="color:#8b0000;">Method '{0}' from '{1}' type is marked with [Transaction] attribute, but is not declared as virtual.</span>",
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 35:                     methodInfo.Name,
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 36:                     methodInfo.DeclaringType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 37:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 38: }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 39: </pre>
</pre>
<p>So far, we&#8217;re pleased with how it works for us. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=31&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>What integration tests should you write first</title>
		<link>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/</link>
		<comments>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 10:18:10 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
				<category><![CDATA[Castle]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/06/18/what-integration-tests-should-you-write-first/</guid>
		<description><![CDATA[Generally, the goal of integration tests is to verify that different application parts are glued well together and interacts as expected. Thus, they are a bit different thing from unit tests that tends to test how a small, separate part is acting. Below are two tests that I can&#8217;t classify to be pure integration tests [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=22&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Generally, the goal of integration tests is to verify that different application parts are glued well together and interacts as expected. Thus, they are a bit different thing from unit tests that tends to test how a small, separate part is acting. Below are two tests that I can&#8217;t classify to be pure integration tests because they touch a sensible part of application/infrastructure configuration like Windsor&#8217;s configuration files and NHibernate&#8217;s mappings. These simple tests can save a lot of time at very initial development stage when application bits are changed frequently and later, as a guarantee that you&#8217;ve not broken something in a recent refactoring.</p>
<h4>Can_resolve_all_services_in_container()</h4>
<p><a href="http://weblogs.asp.net/bsimser/default.aspx">Bill Simser</a> wrote some time ago about <a href="http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx">the first test to be written when using Castle&#8217;s Windsor Container</a>. It&#8217;s a real gem that let&#8217;s you verify if any of services registered in container can be resolved (have all required dependencies). Here is it, a bit improved for skipping verification for generic types, since, at that moment, we don&#8217;t know the generic argument for type to be constructed:</p>
<pre class="code">[<span style="color:#2b91af;">Test</span>]
<span style="color:blue;">public void </span>Can_resolve_all_services_in_container()
{
    <span style="color:blue;">var </span>container = <span style="color:blue;">new </span><span style="color:#2b91af;">WindsorContainer</span>(<span style="color:#a31515;">"container.xml"</span>);
    <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">IHandler </span>handler <span style="color:blue;">in </span>container.Kernel.GetAssignableHandlers(<span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>)))
    {
        <span style="color:blue;">if </span>(handler.ComponentModel.Service.IsGenericType)
            <span style="color:blue;">continue</span>;

        container.Resolve(handler.ComponentModel.Service);
    }
}
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h4>Can_compile_NHibernate_mapping_configuration()</h4>
<p>This test was sitting for a long time in our codebase, but I&#8217;ve seen it recently in <a href="http://codebetter.com/blogs/david_laribee/archive/2008/06/17/test-your-nhibernate-mappings.aspx">this post</a> of <a href="http://codebetter.com/blogs/david_laribee/default.aspx">David Larebee</a>. I wrote it in times when writing our first mappings and the only one way to verify if you don&#8217;t have any faults was to write one of CRUD operations and run the test. But that&#8217;s a long process. Shorter response cycle is always better. Here it is:</p>
<pre class="code">[<span style="color:#2b91af;">Test</span>]
<span style="color:blue;">public void </span>Can_compile_NHibernate_mapping_configuration()
{
    <span style="color:#2b91af;">ISessionFactory </span>factory =
        <span style="color:blue;">new </span><span style="color:#2b91af;">Configuration</span>()
            .Configure()
            .AddAssembly(<span style="color:#a31515;">"MyApp.MyDomainAssembly"</span>)
            .BuildSessionFactory();

    <span style="color:#2b91af;">Assert</span>.IsNotNull(factory);
}
</pre>
<p>This test suppose that you have HNibernate configuration in your app.config and tries to register all mappings from given assembly file.</p>
<p>&nbsp;</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&amp;blog=1485392&amp;post=22&amp;subd=varely&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
	</channel>
</rss>
