<?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>Rのメモ帳 &#187; トラブルシューティング（プログラミング）</title>
	<atom:link href="http://brandish.xrea.jp/wordpress/?cat=7&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://brandish.xrea.jp/wordpress</link>
	<description>Regihsが送るぐだぐだな日々の中で思いついたことを書き綴るページです。</description>
	<lastBuildDate>Wed, 25 Jul 2012 01:19:38 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>JUnit4のテストとコンストラクタ</title>
		<link>http://brandish.xrea.jp/wordpress/?p=211</link>
		<comments>http://brandish.xrea.jp/wordpress/?p=211#comments</comments>
		<pubDate>Thu, 30 Jun 2011 08:22:00 +0000</pubDate>
		<dc:creator>regihs</dc:creator>
				<category><![CDATA[トラブルシューティング（プログラミング）]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[プログラミング]]></category>

		<guid isPermaLink="false">http://brandish.xrea.jp/wordpress/?p=211</guid>
		<description><![CDATA[Spiderの開発では、JUnit4による自動テストを行っています。オブジェクトの検索処理が心臓部となるので、その正確性を確認しておかなければなりませんし、性質上テストしやすいものでもあるからです。 JUnit4は、アノ &#8230; <a href="http://brandish.xrea.jp/wordpress/?p=211">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Spiderの開発では、JUnit4による自動テストを行っています。オブジェクトの検索処理が心臓部となるので、その正確性を確認しておかなければなりませんし、性質上テストしやすいものでもあるからです。</p>
<p>JUnit4は、アノテーションを使ってテストメソッドなどを指定します。具体的には、<code>@Test</code>を付したメソッドはテストされ、<code>@Before</code>や<code>@After</code>を付したメソッドはテストメソッドの実行前後に呼び出されます。</p>
<p>ここで、見落としがちなのは、テストメソッドを有するテストクラスのコンストラクタがいつ呼び出されるのか、という点です。</p>
<p>わたしの認識では、何度もテストクラスのオブジェクトを構築するのは無駄ですから、テストクラスのオブジェクトが構築されると、以後、そのオブジェクトが使い回されるものと思っていました。しかし、実際には、<strong>テストメソッドを実行するたびに新たなテストクラスのオブジェクトが構築されます</strong>。これを見落とすと、初期化されているはずのフィールドが初期化されていなかったり、値を設定したはずのフィールドに何も設定されていないという事態が生じることになります。</p>
<p>なお、<a href="http://kentbeck.github.com/junit/javadoc/latest/org/junit/Test.html">JUnit4のAPIリファレンス</a>には、「To run the method, JUnit first constructs a fresh instance of the class then invokes the annotated method.」と書かれており、アノテーションが付されたメソッドを呼び出すときには、JUnitは新しいインスタンスを生成するということが明記されています。その他に、このことについて言及しているドキュメントはあったのでしょうか。自分としては、見かけませんでした。</p>
]]></content:encoded>
			<wfw:commentRss>http://brandish.xrea.jp/wordpress/?feed=rss2&#038;p=211</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
