<?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>Schauderhaft &#187; continuous integration</title>
	<atom:link href="http://blog.schauderhaft.de/tag/continuous-integration/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.schauderhaft.de</link>
	<description>Softwaredevelopment, Projectmanagement, Qualitymanagement and all things &#34;schauderhaft&#34;</description>
	<lastBuildDate>Sun, 22 Jan 2012 19:13:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Tips for Testing Database Code</title>
		<link>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/</link>
		<comments>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/#comments</comments>
		<pubDate>Sun, 15 Jan 2012 05:52:33 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=1013</guid>
		<description><![CDATA[Almost everybody understands that source code belongs into version control. Many people understand we need to test our code. Quite a few do that automatically. But everything seems to change when it comes to databases. A lot of stuff in and around databases goes untested. Heck some of the scripts don&#8217;t even live in version [...]]]></description>
			<content:encoded><![CDATA[<p>Almost everybody understands that source code belongs into version control. Many people understand we need to test our code. Quite a few do that automatically.</p>
<p>But everything seems to change when it comes to databases. A lot of stuff in and around databases goes untested. Heck some of the scripts don&#8217;t even live in version control. If you can&#8217;t believe that, because you haven&#8217;t seen it, you are a damn lucky bastard.</p>
<p>At least one reason for this state of affairs is obviously: It hurts. Database tests tend to be slow, interdependent and hard to maintain. Granted. But you know what: If it hurts, you should do it more often. It will teach you what exactly the things are that cause pain when testing and eventually you&#8217;ll find approaches to make it less painful. Here are some ideas I found helpful when testing database related code:</p>
<ul>
<li>Give every developer her own database. This forces you to find a way to set up the database fast, easy and reliable. If your application lives in a single user/schema/namespace it is sufficient for each developer to have his own user/schema/namespace in a single database. For this to work though &#8230;</li>
<li>&#8230; the application should be user/schema/namespace agnostic. It makes it much easier to create multiple instances one a single server.</li>
<li>Let the application live in a single user/schema/namespace. If you have multiple interdependent namespaces (e.g. for modules) you&#8217;ll have a hard time making them agnostic of the names.</li>
<li> Have separate instances for CI, Demos, QA and so on. Actually ideally it should be trivial to create a fresh instance.</li>
<li>Stay away from any tool that comes with its own repository. If have seen about a dozen of such tools and although some looked promising in the beginning, they all completely failed to integrate with other tools on the development side of things. Examples of such tools are tools for code generation from <a href="http://en.wikipedia.org/wiki/Unified_Modeling_Language">UML</a> or <a href="http://en.wikipedia.org/wiki/Entity-relationship_model">ER</a> models and <a href="http://en.wikipedia.org/wiki/Extract,_transform,_load">ETL</a> tools.</li>
</ul>
<p>The previous points where about the setup of your database and infrastructure. Lets have a look at the code:</p>
<ul>
<li> Favor a proper Language (like Java, C, PHP &#8230;) over database specific languages like T-SQL or PL/SQL. If you are wondering why, make a comparison between your favorite DB language and your all purpose language. For which do you get the better IDE, Unit testing support, code analysis, code coverage and so on. Reconsider your main language if it doesn&#8217;t win in that comparison.</li>
<li> Have a small layer that does all interaction with the database. Make sure no SQL or other database dependent code leaks out. Inject that layer as a dependency into anybody in need of it. This will allow you to test almost everything without worrying about the database. Only the tests for that integration layer actually needs a database for testing.</li>
<li>Favor database independent SQL or a library abstracting away the differences of various databases. Back in the time people claimed they needed that in case they have to switch database vendors, which never happened. Now it does. See below.</li>
</ul>
<p>The next points will deal with the actual tests:</p>
<ul>
<li>Consider an in-memory-database for testing. Many databases can run in an in-memory-mode. They are great for testing, because you can throw them away after the test, and they are way faster then any database writing to disk. This of course is only possible when you work with a database system that can run as a in-memory-database or if your code is database independent. Hence the previous point.</li>
<li>If you can&#8217;t use your database as in memory database, consider putting it on a RAM disk. We got a huge performance gain for our tests with this approach. A solid state disk might be the next best thing although I&#8217;m not sure how it would react to the heavy load of continuous database tests.</li>
<li>Make test failure messages so explicit that you don&#8217;t have to look into the database for analyzing test failures.</li>
<li>Use code for setting up your test data. Make it nice and concise. If you need a row in a table without special requirements for its values you should be able to create that with a single trivial line of code, no matter how many foreign keys the table contains. I.e. you should have a little <a href="/2011/03/20/testing-databases-with-junit-and-hibernate-part-2-the-mother-of-all-things/">DSL for your test data</a>. Doing it with plain code will enable all the refactoring power of your IDE for your tests. For load and performance tests other approaches like loading production data or large amounts of generated data might be suitable.</li>
<li>Make sure your tests clean up after them selves. There are two approaches I found usable in most cases:</li>
</ul>
<blockquote>
<ol>
<li>Recreate the schema for every test. This is slow but really safe.</li>
<li>Do a rollback after each test. This only works when there is no commit inside the test. The mean thing is: If a test tries to rollback, but fails because there was a commit inside the test some completely different test will fail. It can be a really frustrating task to find the bad test in such a case.</li>
</ol>
</blockquote>
<p>We covered the testing of  database related code inside your application. But there is another kind of code we need to deal with: Scripts for deploying your application (or upgrading it)</p>
<ul>
<li>The scripts that change your database schema from one version to the next are source code just like everything else. Therefore they belong under version control and should get tested continuously.</li>
<li>The testing process is really simple: Create a database as it looks now. Apply your change scripts and verify it looks as desired.</li>
<li>For verifying the resulting schema it is useful to have a script that creates your target database (or at least the schema) from scratch, so you compare it with the result of the test.</li>
<li>For performance reasons you might want to test this with an empty database first.</li>
<li>But don&#8217;t forget to run it on an instance with realistic data as well. Hint: adding a column to huge tables can take loooooong.</li>
</ul>
<p>Happy testing everybody.</p>
<blockquote><p>&nbsp;</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2012/01/15/tipps-for-testing-database-code/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Are You a Software Developer or a Dabbler</title>
		<link>http://blog.schauderhaft.de/2009/11/01/are-you-a-software-developer-or-a-dabbler/</link>
		<comments>http://blog.schauderhaft.de/2009/11/01/are-you-a-software-developer-or-a-dabbler/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 08:38:23 +0000</pubDate>
		<dc:creator>Jens Schauder</dc:creator>
				<category><![CDATA[Softwaredevelopment]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[dabbler]]></category>
		<category><![CDATA[good practice]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[software development]]></category>
		<category><![CDATA[solid software]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[version control system]]></category>

		<guid isPermaLink="false">http://blog.schauderhaft.de/?p=307</guid>
		<description><![CDATA[When reading blogs you get the impression, that everybody works in high end environments, using the latest greatest distributed version control system. Writing tons of tests, before they even dream about writing actual code and of course the tests a executed by the continuous integration system after every commit, which happens about 30 times per [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_308" class="wp-caption alignleft" style="width: 310px"><a href="http://www.sxc.hu/photo/289526"><img class="size-medium wp-image-308" title="289526_6178" src="http://blog.schauderhaft.de/wp-content/uploads/2009/10/289526_6178-300x225.jpg" alt="Tools" width="300" height="225" /></a><p class="wp-caption-text">Tools</p></div>
<p>When reading blogs you get the impression, that everybody works in high end environments, using the latest greatest distributed version control system. Writing tons of tests, before they even dream about writing actual code and of course the tests a executed by the continuous integration system after every commit, which happens about 30 times per day and developer. But when I look around in the real world, this is not <a href="/2009/09/20/your-perspective-is-biased/">what I see</a>. Instead the way people work on their code like ancient &#8216;doctors&#8217;. Drilling holes in heads in the hope it will reduce the headache of the patient. It probably did. In many cases in a very final way. I urge you: Don&#8217;t let that happen to your code (or your career). Practice solid software development. And in order to help you with that I compiled a simple list of things you really really should do. Those are basic practices. If you don&#8217;t even adhere to those then I have only two possible explanations: You are not involved in software development at all. Go away, this blog isn&#8217;t for you. Or &#8230; you are a dabbler.</p>
<ul>
<li>Use a Version Control System (VCS). I am not even going to comment on this one.</li>
<li>Commit your changes at least once a day. This does not mean you should commit what ever is on your filesystem at 5pm, but you should break your tasks in so small pieces, that you finish one or two of them on a normal day.</li>
<li>Tag or label everything in the VCS you hand out to somebody outside your team (testers, salespersons and of course customers)</li>
<li>Have a complete and working build script. This means you can build everything you hand of to the customer by getting the source code out of the VCS and start the script. Necessary adjustments are made in a tiny file which contains settings for the local machine. A well commented template for such a file is in the VCS. And NO, hitting the compile button in your IDE is not the same as a build script.</li>
<li>You must have the complete environment necessary to run your application under your control. That means if your application needs a database, you have a database available. One per developer that is, or at least one schema per developer. If you need a queue or ten queues, you have those, again once for every developer. If you have systems that you interface to, that can&#8217;t be installed once per developer, you have mocks, stubs or similar available. In the year 2009 a single developer database for 5 developers is no longer acceptable.</li>
<li>You have an extensive set of automatic Unit tests. These test should cover at the minimum the main execution paths.</li>
<li>Let a Continuous Integration system execute your build script, i.e it compiles your code, executes the automatic tests and builds a setup or jar, or what ever you are deploying.</li>
<li>Have a specification of what a piece of software is supposed to do, before you try to write the software. You don&#8217;t need a full specification of the complete application upfront. Maybe you have just the first user story for the first feature, or only a test. But you must have something that tells you where to go. And where not to go. Flying blindfolded is not the same as being agile.</li>
<li>Adhere to a style guide that describes your naming conventions, indenting and so on. Ideally this gets enforced by the IDE and automatic tests. Fighting about the content of such code conventions is useless. Not having one is dumb. Remember that your tests are code too, so the conventions apply to tests as well.</li>
<li>Document how your code is structured. It should at least describe the different layers, and the way two layers may depend on each other, and it should not allow for circular dependencies. These rules as well should be enforced by automatic tests. Even if the language you use doesn&#8217;t support packages you should use a similar concept, possibly through naming conventions.</li>
</ul>
<p>These are my points. What did I miss?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.schauderhaft.de/2009/11/01/are-you-a-software-developer-or-a-dabbler/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

