On 22/06/2011, at 8:46 PM, netextzhwa wrote:

> Hey guys,
> 
> I'm having a wield problem on the executing sequence in afterTest method of
> Test task.
> 
> I have three tasks, two Test task runs the same Geb+junit test, the other is
> a action simply print a message.
> 
> They are follows:
> 
> task testA(type: Test ) {
>       testA.ignoreFailures = true
>       testA.afterTest{ TestDescriptor descriptor, TestResult result ->
>               if 
> (TestResult.ResultType.FAILURE.equals(result.getResultType())) {
>                       println "A1"
>                       if(test.getName()!="classMethod"){
>                               println "A2"
>                               sleep 5000
>                               testB.execute()
>                               println "A3:return from testB"
>                               return
>                       }
>               }else {
>                       println "A4"
>                       return
>               }
>       }
> }
> 
> task testB(type: Test ) {
>       testB.ignoreFailures = true
>       testB.afterTest{ TestDescriptor descriptor, TestResult result ->
>               if 
> (TestResult.ResultType.FAILURE.equals(result.getResultType())) {
>                       println "B1"
>                       if(test.getName()!="classMethod"){
>                               println "B2"
>                               sleep 5000
>                               notATest.execute()
>                               println "B3: return from notATest"
>                               return
>                       }
>               }else {
>                       println "B4"
>                       return
>               }
>       }
> }
> 
> task notATest() << {  
>               println "do notATest "
> }
> 
> 
> So when I run testA, it starts with running the test, and when the test
> fails, 
> 
> it prints:
> "A1"
> "A2"
> then sleep for 5 seconds and continue with running testB, the test fail
> again, and then it prints:
> "B1"
> "B2"
> then sleep for 5 seconds and goes into task notATest, and print:
> "do notATest"
> then it returns testB and prints:
> "B3: return from notATest"
> 
> So far so good! However, it keep working to print:
> "B1"
> "B2"
> "B3"
> This now is very wield, it goes back to the start of testB's testListener
> and print those message again! And it does not print "do notATest", which
> means it only print message in testB, but not go to further method call
> again!?
> 
> The rest of running is similarly wield:
> goes back to caller testA and print:
> "A3:return from testB"
> "A1"
> "A2"
> sleep 5 sec, but not goes into testB again, keep print:
> "A3:return from testB"
> and then end.
> 
> What could be the reason of this?

I suspect you are expecting your “return” statements to halt the execution of 
your task, which is not the case.

In Groovy, when you “return” in a closure, you are only exiting the closure and 
not the containing method. So instead of “return” stopping the test run, it is 
just exiting the listener and then moving on to the next test.

The reason that you don't see “do notATest” more than once is that you can only 
execute a task once.


The way that this is currently arranged is not very Gradle like. You should 
avoid directly executing tasks wherever possible. It's not clear to me what you 
are trying to achieve or what problem you are trying to solve. If you can 
explain what your problem is and what behaviour you want we can hopefully 
suggest a better way of achieving it.

-- 
Luke Daley
Principal Engineer, Gradleware 
http://gradleware.com

Please vote Gradle for JAX Awards » http://vote.jax-awards.com


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to