Spock + TestVerticle

364 views
Skip to first unread message

Jens Geiregat

unread,
Nov 6, 2014, 4:28:42 AM11/6/14
to ve...@googlegroups.com
Hi all,

I was wondering if anyone succeeded in creating a Spock-compatible version of the TestVerticle from testtools? We would like to write some integration tests, but the rest of the tests are written in Spock, and we like Spock. :) So we would like to use it for our integration tests too. I investigated if the Spock Specification base class and the TestVerticle class could be merged easily but unfortunately that's not the case it seems...

Kind Regards,


Jens

Nick Scavelli

unread,
Nov 6, 2014, 9:27:39 AM11/6/14
to ve...@googlegroups.com
Our testing in Vert.x 3 is a lot simpler, so maybe this is more achievable with version 3 ?

Alexander Lehmann

unread,
Nov 6, 2014, 2:53:02 PM11/6/14
to ve...@googlegroups.com
I thought about using jbehave with vert.x a while back, but I am not sure how to integrate a test framework with vert.x without causing problems in the async operation.
The same probably applies to spock and other test frameworks.

Nick Scavelli

unread,
Nov 6, 2014, 3:02:35 PM11/6/14
to ve...@googlegroups.com
Yea good point. The async nature of vertx makes testing frameworks a pain to work with.

Alexander Lehmann

unread,
Nov 6, 2014, 5:03:38 PM11/6/14
to ve...@googlegroups.com
Maybe it would be possible to have a extension for Spock to use vert.x similar to the junit runner.
Have to look a bit more at how Spock works if that is possible.

Tim Fox

unread,
Nov 7, 2014, 2:57:54 AM11/7/14
to ve...@googlegroups.com
Yeah, most testing frameworks are firmly anchored in the 90s/00s and seem not to have even noticed that a lot of stuff is async these days. I have yet to find a decent Java test framework that can handle async tests out of the box. (Hint: Maybe there is room in the market for a new test framework?)

In Vert.x 3.0 we solve this by having our test base class which has a few useful methods for async tests, so you can do stuff like:

https://github.com/eclipse/vert.x/blob/master/vertx-core/src/test/java/io/vertx/test/core/AsyncTestBaseTest.java#L105

I.e. you can call assertXXX(...) and fail(...) on threads other than the main test thread. You can't do this in normal JUnit as Junit assertXXX calls throw assertException which isn't caught by Junit unless it's on the Junit thread.

So we provide our own version of each assertXXX which captures whether the assert succeeded or passed. Then when your test is complete you call testComplete(), and you call await() at the end of your test to stop it exiting.

When the test is complete, the JUnit thread on waiting on await() wakes up and if any asserts have failed it will rethrow the AssertException this time from the main thread.

Anyway.... all this stuff should be in a real test framework.
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alexander Lehmann

unread,
Nov 7, 2014, 1:23:15 PM11/7/14
to ve...@googlegroups.com
I wonder if wrapping the tests in Rx would make it easier to run it in a framework?

Julien Viet

unread,
Nov 8, 2014, 3:10:28 AM11/8/14
to ve...@googlegroups.com, Tim Fox
I just spent 10 mns encapsulating in a Junit 4 Rule the Vert.x 3 async test part : https://github.com/vietj/vertx-asyncunit/blob/master/src/test/java/io/vertx/test/asyncunit/AsyncRuleTest.java

does it make sense to have this  ?

--
Julien Viet
www.julienviet.com

Tim Fox

unread,
Nov 8, 2014, 3:22:48 AM11/8/14
to Julien Viet, ve...@googlegroups.com
Could you explain a bit more about it? as I'm not really sure what it does.

Julien Viet

unread,
Nov 8, 2014, 3:28:30 AM11/8/14
to ve...@googlegroups.com, Tim Fox
it just takes the part of code in vertx 3 in a junit rules : https://github.com/junit-team/junit/wiki/Rules

rules are a kind of “interceptor” of junit flow.

--
Julien Viet
www.julienviet.com

Tim Fox

unread,
Nov 8, 2014, 3:34:05 AM11/8/14
to Julien Viet, ve...@googlegroups.com
I see, so the advantage is that the developer doesn't have to call
await() at the end of the test, but the disadvantage is they have to do
this:

rule.assertEquals("foo", "bar");

or

rule.fail("blah");

as opposed to invoking the method on the super class (AsyncTestBase)

Jens Geiregat

unread,
Nov 9, 2014, 2:46:52 PM11/9/14
to ve...@googlegroups.com, Julien Viet
Thanks for all the replies so far! I took Julien's AsyncRule and added some code that creates a PlatformManager, starts my module(s) and waits an ugly 2s delay to wait for all verticles to be ready. This initialization happens when the Rule is constructed so the module(s) are started only once per class. I moved the .await() from the AsyncStatement to the "then:" part of my Spock specification and things seem to work now: the AssertionErrors are thrown in the correct part of the Spock test. My code is still a mess, but when I have played around with it a bit more I will try to extract an updated AsyncRule. It might be cleaner also to extract the whole 'start module and wait' code to a different rule though and keep AsyncRule mostly as-is.


.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x"
group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

   

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/Gg8BxFAc_Js/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+unsubscribe@googlegroups.com.

Kirk Stork

unread,
Sep 19, 2015, 2:11:14 PM9/19/15
to vert.x, jul...@julienviet.com
This thread is pretty old, but it is the most recent mention of Spock I found in the group.

Nowadays, Spock has an async capability

There's a microscopic example here:  https://github.com/kastork/vertx3-spock-example


.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "vert.x"
group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/Gg8BxFAc_Js/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.

Jens Geiregat

unread,
Sep 20, 2015, 2:16:34 AM9/20/15
to ve...@googlegroups.com
Hi Kirk,

It indeed is fascinating. Thanks for sharing this! I will give it a try myself.

Kind Regards,


Jens

Reply all
Reply to author
Forward
0 new messages