[Hawkular-dev] Assertj framework

Michael Burman miburman at redhat.com
Tue Sep 6 11:19:27 EDT 2016


Hi,

While it's nice to have easier tests, this does not really work for metrics as we use RxJava and AssertJ has no support for any reactive frameworks. The assertJ provides next to nothing in that context, as most of our implementation is reactive in behavior. There are two projects that have tried to improve situation with RxJava, one abandoned because the author thinks TestSubscriber is better and second one is quite incomplete.

We don't currently write our tests well, that's true. We should be using TestSubscriber in multiple place instead of our current .toBlocking().lastOrDefault(null) (workaround). I really don't want the latter to be used more, since it's used in situations where it shouldn't be. Tests should be reactive just like our other code, and AssertJ can't provide that.

  -  Micke

----- Original Message -----
From: "Joel Takvorian" <jtakvori at redhat.com>
To: "Discussions around Hawkular development" <hawkular-dev at lists.jboss.org>
Sent: Tuesday, September 6, 2016 5:24:16 PM
Subject: [Hawkular-dev]  Assertj framework

Hello, 

I'd like to propose the addition of the "assertj" lib in test scope for hawkular-metrics (and/or other modules). 

If you don't know it, assertj is basically a "fluent assertion framework". You write assertions like : 

assertThat(result) . extracting( DataPoint :: getTimestamp) . containsExactly( 0L , 1L , 5L , 7L , 10L ); 

It has a very rich collection of assertions, I find it particularly powerful when working on collections, whether they are sorted or not, whether they have nested objects or not. 

Also, the fact that it's "fluent" helps a lot when you write a test, because your IDE auto-completion will help you a lot to find what's the assertion you're looking for - something that is not so easy with hamcrest. 

I see it as a kind of virtuous cycle: tests are easier to write, easier to read, so you write more tests / better tests. 

Would you be ok to give it a try? 

If you want to read about it: official site is there http://joel-costigliola.github.io/assertj/ 
or an article that promotes it nicely : https://www.infoq.com/articles/custom-assertions 
or an example of file I'd like to push, if you're ok with assertj :) : https://github.com/jotak/hawkular-metrics/blob/72e2f95f7e19c9433ce44ee83d15a9978503d9f5/core/metrics-core-service/src/test/java/org/hawkular/metrics/core/service/MetricsServiceImplTest.java 

Joel 

_______________________________________________
hawkular-dev mailing list
hawkular-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hawkular-dev


More information about the hawkular-dev mailing list