axon-jgiven - BDD testing for axon-test (open source extension)

56 views
Skip to first unread message

Jan Galinski

unread,
Jul 21, 2019, 10:00:51 PM7/21/19
to Axon Framework Users
Axon comes with a great fixture test tool that provides a fluent, bdd styled (given/when/then) API to write aggregate and saga tests. So far, so great.

JGiven on the other hand provides a great java based test tool for junit/junit5 that supports strict type safe separation of the different Arrange/Action/Assert  Stages and also great reports that can be used to document features.


Knowing these two tools, I came up with "axon-jgiven" ... writing axon tests the jgiven way (written in kotlin and primarily addresses kotlin, but should also be usable with java). This is how a test of the giftcard example looks like using axon-jgiven:

class GiftcardSampleScenarioTest : AggregateFixtureScenarioTest<GiftcardAggregate>() {

@ProvidedScenarioState
val fixture: AggregateTestFixture<GiftcardAggregate> = AggregateTestFixture(GiftcardAggregate::class.java)

@Test
fun `issue command creates aggregate`() {
GIVEN
.noPriorActivity()

WHEN
.command(IssueCommand("1", 100))

THEN
.expectEvent(IssuedEvent("1", 100))
.AND
.expectState(GiftcardAggregate("1", 100))
}
}

running this test gives you a console report:

Test Class: io.toolisticon.addons.axon.jgiven.GiftcardSampleScenarioTest

 Issue command creates aggregate

   Given no prior activity
    When command: "IssueCommand(id=1, initialBalance=100)"
    Then expect event: "IssuedEvent(id=1, initialBalance=100)"
     And expect state: "GiftcardAggregate(id=1, balance=100)"


and also the generated, browsable html report:

Bildschirmfoto 2019-07-21 um 23.52.27.png


I released the first version 0.1.1 based on axon 4.1.2 and jgiven 0.17.1 on bintray


repositories {
  maven("https://dl.bintray.com/toolisticon/maven/")
}
dependencies {
  testImplementation("io.toolisticon.addons.axon:axon-jgiven:0.1.1")
}

and it should also be available on jcenter soon.

The project is available on github https://github.com/toolisticon/axon-addons  under the derived BSD-3 license.

I am really interested in your feedback. Currently, I only support junit5, biut I am open for suggestions and pull requests.

So: what do you think?

Jan

Steven van Beelen

unread,
Jul 22, 2019, 9:20:47 AM7/22/19
to Axon Framework Users
Hi Jan,

> So: what do you think?
I think it is super awesome you're sharing such a tool you've been working on with the rest of the community!
Thus I highly applaud your effort and hope others can benefit from your work too.

Keep us posted if new, interesting stuff occurs with this project you're working on! :-)

Cheers,
Steven

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/axonframework/8ea5b6b1-9279-40ed-840e-c57f5e9ccc22%40googlegroups.com.

Jan Galinski

unread,
Jul 22, 2019, 12:35:51 PM7/22/19
to Axon Framework Users
Hi Steven, thanks for the applause ...  will keep you posted.

Jan 

Polish Civil

unread,
Jul 22, 2019, 12:49:15 PM7/22/19
to axonfr...@googlegroups.com
Would love to see property driven testing with axon. I've seen  some people talking they have it implemented for the axon to produce randomized payloads of data, im guessing nothing public.

Seeing what you did there on the bdd, i do not think that the checking state is that important for aggregates, mostly they are black boxes which just publish certain events, this is why property based testing would be perfect addition for axon.

Good luck with your thing :) I'm not sure though why people are doing test frameworks, everything you posted i can do with plain JUnit.


pon., 22 lip 2019 o 14:35 Jan Galinski <jan.ga...@holisticon.de> napisał(a):
Hi Steven, thanks for the applause ...  will keep you posted.

Jan 

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

Jan Galinski

unread,
Jul 22, 2019, 12:56:06 PM7/22/19
to Axon Framework Users

Am Montag, 22. Juli 2019 14:49:15 UTC+2 schrieb Polish Civil:
Would love to see property driven testing with axon. I've seen  some people talking they have it implemented for the axon to produce randomized payloads of data, im guessing nothing public.

Seeing what you did there on the bdd, i do not think that the checking state is that important for aggregates, mostly they are black boxes which just publish certain events, this is why property based testing would be perfect addition for axon.

Good luck with your thing :) I'm not sure though why people are doing test frameworks, everything you posted i can do with plain JUnit.


Well, state of aggregate testing was not the goal here ... the main benefit is to combine the fluent axon-test api with the power of jgiven. All methods that are provided by the axon-test fixture are also supported by my lib, you might want to check out the test sources on github for more examples.

Of course all of this could be done with plain junit, but I like how jgiven helps to write reusable steps that are clearly separated into given/when/then scopes - and the advanced readability and reporting it gives me ... so basically this lib is "syntactic sugar". But I like it that way, maybe someone else will like it too.

The property based approach would in deed be interesting.

Thanks for your thoughts

Jan
Reply all
Reply to author
Forward
0 new messages