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
<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


Any tips on how to make this work?

Thanks,
Geoff.
6 comments
Comment actions Permalink

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:

<target name="features">
    <java classname="org.jruby.Main" fork="true" failonerror="true">
      <classpath>
        <pathelement path="${jruby.home}/lib/jruby.jar"/>
        <pathelement path="${jruby.home}/lib/ruby/gems/1.8/gems/jvyaml-0.0.1/lib/jvyamlb.jar"/>
        ....
      </classpath>
      <jvmarg value="-Xmx512m"/>
      <jvmarg value="-XX:+HeapDumpOnOutOfMemoryError"/>
      <jvmarg value="-ea"/>
      <jvmarg value="-Djruby.home=${jruby.home}"/>
      <arg value="-S"/>
      <arg value="cucumber"/>
      <arg value="--format"/>
      <arg value="Teamcity::Cucumber::Formatter"/>
      <arg value="--expand"/>
      <arg value="."/>
      <env key="RUBYLIB" value="${agent.home.dir}/plugins/rake-runner/lib/rb/testing/patch/common;${agent.home.dir}/plugins/rake-runner/lib/rb/testing/patch/bdd"/>
    </java>

  </target>


0
Comment actions Permalink

Thanks Roman.  So do we still need a Rake wrapper to trigger the Ant build?

0
Comment actions Permalink

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] undefined method `create_custom_progress_tests_category' for Rake::TeamCity::MessageFactory:Module (NoMethodError)
[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:

/Users/garnold/Development/IM/code/conf/vms/ruby/jruby-1.3.1/bin/jruby -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) /Users/garnold/Development/IM/code/extranet/script/cucumber /Users/garnold/Development/IM/code/extranet/features/ab_test_reporting.feature --format Teamcity::Cucumber::Formatter --expand --color
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
0
Comment actions Permalink

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.

0
Comment actions Permalink

This exception was due to an old version of the Cucumber formatter in our project.

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?

however I am still not seeing the Cucumber tests in TeamCity.  Could you please give more detail on your setup?

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}

0
Comment actions Permalink

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>

    </target>

Thanks for your help,
Geoff.
0

Please sign in to leave a comment.