Testing with Spock (Groovy)?

317 views
Skip to first unread message

Alex Sanchez

unread,
Mar 20, 2014, 9:52:13 AM3/20/14
to axonfr...@googlegroups.com
Is anyone testing using the Spock Framework and Groovy?

I'm building a system based on Axon and I use Spock for all my tests.
The BDD-like API for testing your Axon components is awesome for Java, but I'm using Groovy so I would prefer to write my tests in a more groovier way (more expressive, easier to read, etc) rather than the Java-way (using the fluent API). Especially when Spock already have Given/When/Then right in the DSL.

Is this possible? Any recommendations on how to use the fixtures (and it's configuration/components) in a non-fluent way?
Has anyone solved this or have any experience from using this approach?

Thanks
/Alex

bui...@gmail.com

unread,
Mar 20, 2014, 3:05:46 PM3/20/14
to axonfr...@googlegroups.com
Hi Alex,

I know people have been using it with Specs2 in Scala. It worked fine there, so I can image Spock in Groovy wouldn't be a problem either. 

Perhaps it's old age ;-), but where is the readability problem in the Given When Then test fixtures?

Cheers,

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

Alex Sanchez

unread,
Mar 21, 2014, 2:57:33 AM3/21/14
to axonfr...@googlegroups.com
Nothing wrong with the readability on the fluent API. It's great when writing your tests in Java.
But lately we've been trying to move away from Java/JUnit for testing, and are using Spock and Groovy exclusively, just because the tests are faster to write and easier to read.
So the Java-way might feel a little... old age like you said :)

So, it's the fixture configuration complex? I'm thinking (if it's not too complex) that I'll give it a shot and try to make Groovy-based fixture. And maybe use/extend Spock to take advantage of the DSL blocks given/when/then...


Thanks Allard
/alex

Allard Buijze

unread,
Mar 21, 2014, 4:53:36 AM3/21/14
to Axon Framework Users
Hi Alex,

the fixture configuration is pretty easy. Probably, the simplest way for you to approach this, is to create an adapter for spock that uses the Axon fixture underneath.

I have to admit that this style of testing is a lot cleaner. I'm not that old, really. Looking forward to seeing how you pull it off. Ping me if you need any help.
Cheers,

Allard

Martin Tilma

unread,
Mar 25, 2014, 3:17:43 PM3/25/14
to axonfr...@googlegroups.com
Hello Alex,

I really like you example and used groovy and spock and geb in the past (not directly for Axon).

The Axon test fixture uses Events in the given part. In your example you use commands in the given part. Do you have a special reason for that?

Regards,

Martin


On 03/21/2014 07:57 AM, Alex Sanchez wrote:
Nothing wrong with the readability on the fluent API. It's great when writing your tests in Java.
But lately we've been trying to move away from Java/JUnit for testing, and are using Spock and Groovy exclusively, just because the tests are faster to write and easier to read.
So the Java-way might feel a little... old age like you said :)

So, it's the fixture configuration complex? I'm thinking (if it's not too complex) that I'll give it a shot and try to make Groovy-based fixture. And maybe use/extend Spock to take advantage of the DSL blocks given/when/then...


Thanks Allard
/alex

On Thursday, March 20, 2014 8:05:46 PM UTC+1, Allard Buijze wrote:
Hi Alex,

I know people have been using it with Specs2 in Scala. It worked fine there, so I can image Spock in Groovy wouldn't be a problem either. 

Perhaps it's old age ;-), but where is the readability problem in the Given When Then test fixtures?

Cheers,

Allard

On 20 mrt. 2014, at 14:52, Alex Sanchez <love..@gmail.com> wrote:

Is anyone testing using the Spock Framework and Groovy?

I'm building a system based on Axon and I use Spock for all my tests.
The BDD-like API for testing your Axon components is awesome for Java, but I'm using Groovy so I would prefer to write my tests in a more groovier way (more expressive, easier to read, etc) rather than the Java-way (using the fluent API). Especially when Spock already have Given/When/Then right in the DSL.

Is this possible? Any recommendations on how to use the fixtures (and it's configuration/components) in a non-fluent way?
Has anyone solved this or have any experience from using this approach?

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

-- 
Martin Tilma
E-mail: mar...@t4is.nl
Telefoon: 030 655 01 06
Website: http://www.martinenels.nl

Alex Sanchez

unread,
Mar 25, 2014, 3:23:38 PM3/25/14
to axonfr...@googlegroups.com
Hi Martin,

You can use either events or commands. From the Reference Guide:

"Alternatively, you may also provide commands as "given" scenario. In that case, the events generated by those commands will be used to event source the Aggregate when executing the actual command under test. Use the "givenCommands(...)" method to provide Command objects."


Best
/Alex

Martin Tilma

unread,
Mar 25, 2014, 3:28:33 PM3/25/14
to axonfr...@googlegroups.com
Hi Alex,

Missed that one, never used it.

How is you progress on the the groovy DSL?

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

-- 
Martin Tilma
E-mail: mar...@t4is.nl
Telefoon: 030 655 01 06
Website: http://www.martinenels.nl
--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Sanchez

unread,
Mar 25, 2014, 3:33:34 PM3/25/14
to axonfr...@googlegroups.com
Yes, like I just told Allard (did the mistake to reply only to him and not in the group - new to google groups :)) :

Right now I’m working on the Restful API for our new project. As soon as we start creating the tests for our new Axon command handlers I will give it a try. 


Best regards 
/Alex

You received this message because you are subscribed to a topic in the Google Groups "Axon Framework Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/axonframework/IXskYs0jK1g/unsubscribe.
To unsubscribe from this group and all its topics, send an email to axonframewor...@googlegroups.com.

Alex Sanchez

unread,
Apr 17, 2014, 3:48:02 AM4/17/14
to axonfr...@googlegroups.com
So, I finally got some time to play with this. This is what I came up with, it’s a DSL that uses the default Axon test fixture classes in the background. You can define your command and events in a static or dynamic way. Note: Due to language limitations in Groovy and current limitations in the Spock Framework I was not able to create the DSL I really wanted. But for Groovy, Spock and Gradle users I think this DSL is very natural and still simple.

Statically: You define the commands and events in your test by using pre-built instances, just like when you use Axon’s fluent API. Since it’s static you get constructor parameters help (autocomplete/intellisense) from your IDE. The downside is that the command/event definition is not that expressive and you have to use the ’new’ keyword. 




Dynamically: This way you don’t need to create instances (no need for the ’new’ keyword). You define your commands by specifying the command/event class and payload separately. The payload is the arguments that will be used to construct an instance, so the arguments must match the class constructor. Arguments can either be named or ordered. This is much more expressive, however, the downside is that you won’t get any context help (constructor parameter help) for your commands/events.




Best regards
Alex Sanchez

Allard Buijze

unread,
Apr 18, 2014, 5:16:58 AM4/18/14
to Axon Framework Users
Hi Alex,

this looks really nice. I'm thinking on how to best include this in the Axon project (assuming that that's what you'd like to do with it).
What I'm wondering is how much any change in the API of the test fixtures (e.g. a new method) would impact the Groovy API.

Cheers,

Allard


Alex Sanchez

unread,
Apr 22, 2014, 3:54:53 AM4/22/14
to axonfr...@googlegroups.com
Hey Allard,

I would happily contribute the source to the Axon project.

Well, my code uses the public API only, no private classes.

Fixture factory class:

org.axonframework.test.Fixtures

Fixture interfaces:

org.axonframework.test.FixtureConfiguration
org.axonframework.test.ResultValidator
org.axonframework.test.TestExecutor

/alex

Nils Plaschke

unread,
Jul 29, 2015, 6:35:13 PM7/29/15
to Axon Framework Users, love...@gmail.com
Are there any news on this? I would love to have access to this dsl

tyler.th...@promontech.com

unread,
Jun 2, 2016, 11:57:02 AM6/2/16
to Axon Framework Users, love...@gmail.com
I'm also super interested in this DSL. Any updates? 

David Hamilton

unread,
Jan 28, 2017, 3:57:18 PM1/28/17
to Axon Framework Users, alex.s...@email.com
Hi Alex,

I'm currently creating/converting a TodoBackend example - http://www.todobackend.com - using Axon/SparkJava/Spock and that DSL example that you created looks great!
Did you even get around to putting that DSL code into a GitHub project or the like?

Cheers
   David

Beka Tsotsoria

unread,
Aug 16, 2020, 8:43:28 AM8/16/20
to Axon Framework Users
Hello,

I'm also very interested to see the result. Alex, could you please re-upload the code snippets to at least get a sense of what you ended up with?

Thanks,
Beka

Reply all
Reply to author
Forward
0 new messages