Attach Cucumber reporter to Ant build?
We are using Cucumber to test a number of Java applications, which are all bootstrapped through an Ant build via the "exec" task. I attempted to write a Rake wrapper to our Ant build to allow us to use the Cucumber reporter, however the Cucumber output was not captured by TeamCity.
Here's the Rake wrapper:
=begin
require 'rake'
task :default => :ant
task :ant do
verbose(true) do
sh("ant -Dlabel=#{ENV["label"]} -emacs")
end
end
=end
Here's the Ant "exec" task:
=begin
Any tips on how to make this work?
Thanks,
Geoff.
Here's the Ant "exec" task:
=begin
<exec executable="${jruby.home}/bin/jruby" dir="${basedir}">
<env key="PATH" path="${jruby.home}/bin:${env.PATH}"/>
<env key="CUCUMBER_OPTS" value="${env.CUCUMBER_OPTS}"/>
<arg value="-J-Djava.awt.headless=true"/>
<arg value="-S"/>
<arg value="cucumber"/>
<arg value="features"/>
</exec>
=end
<env key="PATH" path="${jruby.home}/bin:${env.PATH}"/>
<env key="CUCUMBER_OPTS" value="${env.CUCUMBER_OPTS}"/>
<arg value="-J-Djava.awt.headless=true"/>
<arg value="-S"/>
<arg value="cucumber"/>
<arg value="features"/>
</exec>
=end
Any tips on how to make this work?
Thanks,
Geoff.
Please sign in to leave a comment.
Hi,
You need just to add correct --format and --expand options to cucumber cmdline args and also specify RUBYLIB env variable pointing on necessary TC Rake runner ruby scripts.
E.g. for RubyMine testing with Cucumber we use:
Thanks Roman. So do we still need a Rake wrapper to trigger the Ant build?
So I believe that I have this setup correctly now, however Cucumber is failing with the following error. Please note that I had to remove the "testing/" directory from the RUBYLIB paths:
[12:16:03]: [Execute ant] /Applications/buildAgent/plugins/rake-runner/lib/rb/patch/bdd/teamcity/cucumber/formatter_03103.rb:24:in `before_features'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/ast/tree_walker.rb:190:in `send_to_all'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/ast/tree_walker.rb:188:in `each'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/ast/tree_walker.rb:188:in `send_to_all'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/ast/tree_walker.rb:179:in `broadcast'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/ast/tree_walker.rb:13:in `visit_features'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/cli/main.rb:56:in `execute!'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/../lib/cucumber/cli/main.rb:24:in `execute'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/cucumber:8
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/cucumber:19:in `load'
[12:16:03]: [Execute ant] /Applications/buildAgent/work/cf3749648290f4d/trunk/integration/artifacts/extranet/jruby/bin/cucumber:19
Also interesting is that IntelliJ 9 fails with the same error when attempting to run Cucumber tests through the IDE:
Testing started at 12:26 PM ...
** Erubis 2.6.5
** Starting Mongrel in test mode at localhost:4000
** Starting Rails in environment test ...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Running Cucumber Tests with Celerity
undefined method `create_custom_progress_tests_category' for Rake::TeamCity::MessageFactory:Module (NoMethodError)
/Users/garnold/Library/Application Support/IntelliJIdea90/ruby/rb/testing/patch/bdd/teamcity/cucumber/formatter_03103.rb:24:in `before_features'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/ast/tree_walker.rb:190:in `send_to_all'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/ast/tree_walker.rb:188:in `each'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/ast/tree_walker.rb:188:in `send_to_all'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/ast/tree_walker.rb:179:in `broadcast'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/ast/tree_walker.rb:13:in `visit_features'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/cli/main.rb:56:in `execute!'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/lib/cucumber/cli/main.rb:24:in `execute'
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/cucumber:8
/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/lib/ruby/gems/1.8/gems/cucumber-0.4.4/bin/cucumber:16:in `load'
/Users/garnold/Development/IM/code/extranet/script/cucumber:16
/Users/garnold/Development/IM/code/extranet/script/cucumber:1:in `load'
-e:1
Empty test suite.
Process finished with exit code 1
This exception was due to an old version of the Cucumber formatter in our project. I removed that library, however I am still not seeing the Cucumber tests in TeamCity. Could you please give more detail on your setup?
Many thanks,
Geoff.
I'm not sure. According your stacktrace you are using cucumber-0.4.4. It seems our formatter wasn't able to find method from [buildAgent]/plugins/rake-runner/lib/rb/patch/common/teamcity/utils/service_message_factory.rb. Could you attach this file?
Take a look on build log. Tests should be mentioned there and will be available in "Overview" and "Tests" tabs of build results. Also tests counter in build results should be greater.
Also please add env variable
{code}
<env key="TEAMCITY_RAKE_RUNNER_MODE" value="buildserver"/>
{code}
Hi Roman,
The "TEAMCITY_RAKE_RUNNER_MODE" environment variable did the trick. Here's our final setup for anyone looking to do the same thing:
TeamCity:
Additional Rake command line parameters: AGENT_HOME=%system.agent.home.dir%
Attached reporters:
Cucumber: ON Cucumber options(CUCUMBER_OPTS): not specified
Rakefile:
require 'rake'
task :default => :ant
task :ant do
verbose(true) do
sh("ant '-Dagent.home.dir=#{ENV["AGENT_HOME"]}' '-Dcucumber.opts=#{ENV["CUCUMBER_OPTS"]}' -emacs")
end
end
build.xml:
<target name="-features">
<exec executable="${jruby.home}/bin/jruby" dir="${basedir}">
<env key="PATH" path="${jruby.home}/bin:${env.PATH}"/>
<env key="RUBYLIB"
path="${agent.home.dir}/plugins/rake-runner/lib/rb/patch/common:${agent.home.dir}/plugins/rake-runner/lib/rb/patch/bdd"/>
<env key="TEAMCITY_RAKE_RUNNER_MODE" value="buildserver"/>
<arg value="-J-Djava.awt.headless=true"/>
<arg value="-S"/>
<arg value="cucumber"/>
<arg line="${cucumber.opts}"/>
<arg value="features"/>
</exec>
Thanks for your help,
Geoff.