You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Stu King <st...@stuartrexking.com> on 2011/03/24 03:50:09 UTC

Pre test task

How would I specify a task to run before / after running my tests for a
project definition? I am using JUnit to run some component tests against a
back end service. I have a Rake task I can call to start / stop the
service.

Say my definition looks like this:

define "document" do
   package :jar

   task :start_service do
     #start some service
   end
end

How would I call :start_service before running my unit tests?

I am an inexperienced ruby developer, so any direction is greatly
appreciated.

Cheers

Re: Pre test task

Posted by Stu King <st...@stuartrexking.com>.
Thanks,

I was not aware of enhance. I solved the problem by using teardown / setup.

Thanks for your help

Stu

On Thu, Mar 24, 2011 at 2:03 PM, Rhett Sutphin <rh...@detailedbalance.net>wrote:

> Hi Stu,
>
> On Mar 23, 2011, at 9:50 PM, Stu King wrote:
>
> > How would I specify a task to run before / after running my tests for a
> > project definition? I am using JUnit to run some component tests against
> a
> > back end service. I have a Rake task I can call to start / stop the
> > service.
> >
> > Say my definition looks like this:
> >
> > define "document" do
> >   package :jar
> >
> >   task :start_service do
> >     #start some service
> >   end
> > end
> >
> > How would I call :start_service before running my unit tests?
>
> define "document" do
>  # ...
>
>  test.enhance [:start_service]
> end
>
> This adds :start_service to the prerequisites list for the test task. This
> the generic way to do what you're asking -- ensure that one task is run
> before another. According to the docs[1], the unit test infrastructure has
> special support for setup and teardown blocks; it sounds like that might
> also work for you.
>
> Rhett
>
> [1]: http://buildr.apache.org/testing.html#setup_teardown
>
> >
> > I am an inexperienced ruby developer, so any direction is greatly
> > appreciated.
> >
> > Cheers
>
>

Re: Pre test task

Posted by Rhett Sutphin <rh...@detailedbalance.net>.
Hi Stu,

On Mar 23, 2011, at 9:50 PM, Stu King wrote:

> How would I specify a task to run before / after running my tests for a
> project definition? I am using JUnit to run some component tests against a
> back end service. I have a Rake task I can call to start / stop the
> service.
> 
> Say my definition looks like this:
> 
> define "document" do
>   package :jar
> 
>   task :start_service do
>     #start some service
>   end
> end
> 
> How would I call :start_service before running my unit tests?

define "document" do
  # ...

  test.enhance [:start_service]
end

This adds :start_service to the prerequisites list for the test task. This the generic way to do what you're asking -- ensure that one task is run before another. According to the docs[1], the unit test infrastructure has special support for setup and teardown blocks; it sounds like that might also work for you.

Rhett

[1]: http://buildr.apache.org/testing.html#setup_teardown

> 
> I am an inexperienced ruby developer, so any direction is greatly
> appreciated.
> 
> Cheers