{"id":539,"date":"2014-04-30T22:00:53","date_gmt":"2014-04-30T21:00:53","guid":{"rendered":"http:\/\/coding.moris.org\/?p=539"},"modified":"2025-01-26T11:53:56","modified_gmt":"2025-01-26T11:53:56","slug":"test-fixtures","status":"publish","type":"post","link":"https:\/\/priscimon.net\/coding\/2014\/04\/30\/test-fixtures\/","title":{"rendered":"Test fixtures"},"content":{"rendered":"<p>I try to avoid the Arrange-Act-Assert (AAA) pattern for unit tests. I find that with multiple test methods depending on the same starting conditions, the &#8216;arrange&#8217; code becomes repetitive, which makes tests tedious to write and difficult to maintain.<\/p>\n<p>My preferred approach is to set one test fixture per test class, the test fixture being common for its test methods. In woodwork a fixture keeps a piece in place whilst it is being worked on; similarly, a test fixture keeps an object in a fixed state as the tests are executed.<\/p>\n<p>Most test frameworks allow a method in a test class to be run before each test method is executed. In JUnit, the decorator <code>@Before<\/code>\u00a0 designates this method; in MSTest, the attribute <code>[TestInitialize]<\/code> has the same effect. This method can be used to configure a test fixture as required for the tests in the class.<\/p>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I try to avoid the Arrange-Act-Assert (AAA) pattern for unit tests. I find that with multiple test methods depending on the same starting conditions, the &#8216;arrange&#8217; code becomes repetitive, which makes tests tedious to write and difficult to maintain. My preferred approach is to set one test fixture per test class, the test fixture being [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-539","post","type-post","status-publish","format-standard","hentry","category-general"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3I4g9-8H","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/comments?post=539"}],"version-history":[{"count":34,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/539\/revisions"}],"predecessor-version":[{"id":1855,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/posts\/539\/revisions\/1855"}],"wp:attachment":[{"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/media?parent=539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/categories?post=539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/priscimon.net\/coding\/wp-json\/wp\/v2\/tags?post=539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}