{"id":243,"date":"2011-01-11T08:17:14","date_gmt":"2011-01-11T15:17:14","guid":{"rendered":"http:\/\/www.connorgarvey.com\/blog\/?p=243"},"modified":"2012-02-13T08:20:42","modified_gmt":"2012-02-13T15:20:42","slug":"functional-integration-tests-in-gradle","status":"publish","type":"post","link":"https:\/\/connorgarvey.com\/blog\/?p=243","title":{"rendered":"Functional Test and Integration Test Targets in Gradle"},"content":{"rendered":"<p><em>* Update February 13th, 2012: Thanks to Ben Ripkens for updates to match the new Gradle API.<\/em><\/p>\n<p>While searching online, I found many suggestions for how to add a new test target to a Gradle script. Most of them were wrong and others didn&#8217;t properly separate the integration test target from standard targets. After not finding a solution, I came up with one on my own.<\/p>\n<p>This example sets up integration tests for Groovy .<\/p>\n<h2>Create a source set<\/h2>\n<p>This will separate the integration test code from other code, allowing it to be built separately.<\/p>\n<ul>\n<li>The classpath in the example gives integration tests access to all application and test classes<\/li>\n<li>The source location will be src\/integrationTest\/groovy<\/li>\n<\/ul>\n<div id=\"wpshdo_1\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_1\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_1\"><\/a><a id=\"wpshat_1\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_1\"  onClick=\"javascript:wpsh_toggleBlock(1)\" title=\"Click to show\/hide code block\">Code block<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_code(1)\" title=\"Show code only\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_print(1)\" title=\"Print code\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_1\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"groovy\" style=\"font-family:monospace;\">sourceSets <span class=\"br0\">&#123;<\/span>\n \u00a0integrationTest <span class=\"br0\">&#123;<\/span>\n \u00a0 \u00a0compileClasspath <span class=\"sy0\">=<\/span> sourceSets.<span class=\"me1\">main<\/span>.<span class=\"me1\">output<\/span> <span class=\"sy0\">+<\/span> configurations.<span class=\"me1\">testRuntime<\/span>\n \u00a0 \u00a0runtimeClasspath <span class=\"sy0\">=<\/span> output <span class=\"sy0\">+<\/span> sourceSets.<span class=\"me1\">main<\/span>.<span class=\"me1\">output<\/span> <span class=\"sy0\">+<\/span> configurations.<span class=\"me1\">testRuntime<\/span>\n \u00a0 \u00a0groovy <span class=\"br0\">&#123;<\/span>\n \u00a0 \u00a0 \u00a0srcDir <span class=\"st0\">'src\/integrationTest\/groovy'<\/span>\n \u00a0 \u00a0<span class=\"br0\">&#125;<\/span>\n \u00a0<span class=\"br0\">&#125;<\/span>\n<span class=\"br0\">&#125;<\/span><\/pre><\/div><\/div>\n<h2>Add the target<\/h2>\n<p>&nbsp;<\/p>\n<div id=\"wpshdo_2\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_2\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_2\"><\/a><a id=\"wpshat_2\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_2\"  onClick=\"javascript:wpsh_toggleBlock(2)\" title=\"Click to show\/hide code block\">Code block<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_code(2)\" title=\"Show code only\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_print(2)\" title=\"Print code\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img decoding=\"async\" border=\"0\" style=\"border: 0 none\" src=\"https:\/\/connorgarvey.com\/blog\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_2\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"groovy\" style=\"font-family:monospace;\">task integrationTest<span class=\"br0\">&#40;<\/span>type: Test<span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span>\n  testClassesDir <span class=\"sy0\">=<\/span> sourceSets.<span class=\"me1\">integrationTest<\/span>.<span class=\"me1\">output<\/span>.<span class=\"me1\">classesDir<\/span>\n  classpath <span class=\"sy0\">=<\/span> sourceSets.<span class=\"me1\">integrationTest<\/span>.<span class=\"me1\">runtimeClasspath<\/span>\n<span class=\"br0\">&#125;<\/span><\/pre><\/div><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>* Update February 13th, 2012: Thanks to Ben Ripkens for updates to match the new Gradle API. While searching online, I found many suggestions for how to add a new test target to a Gradle script. Most of them were wrong and others didn&#8217;t properly separate the integration test target from standard targets. After not [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"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":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[59],"tags":[44,47,48,4],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-java","tag-build","tag-gradle","tag-groovy","tag-java"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1ql2n-3V","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=243"}],"version-history":[{"count":7,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":247,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/243\/revisions\/247"}],"wp:attachment":[{"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/connorgarvey.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}