-
Notifications
You must be signed in to change notification settings - Fork 260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Write a comparison to Kluent, AssertK, Strikt, Atrium, Kotest, other Kotlin assertion libraries? #849
Comments
Dumping a couple scraps of information: First, on multiplatform: KMP supportNo KMP supportSecond, a series (still in progress) that compares Kotlin assertion libraries: |
I should note that I've been ignoring HamKrest for some of the reasons discussed in https://truth.dev/comparison#vs-hamcrest. Mainly, I still worry about its less effective autocompletion. My second possible concern would be that the failure messages may still be complex, but it's possible that that's been improved, and I haven't checked. The one concern that doesn't carry over is that, as the HamKrest site notes, generics for On that note: I got worried because I saw Kotest assertions written in a Hamcrest style: |
It's also worth noting (though veering slightly off-topic) that the built-in kotlin.test provides a richer set of assertion functions than some of us are used to from the JUnit 4 world (and probably even the JUnit 5 world, since the JUnit 5 developers are trying not to go too far down the road of providing assertions). |
More scattered thoughts from looking into parts of the "KMP support" libraries: Assertions as extension methodsI confirmed that assertions are implemented with extension methods. (For AssertK and Atrium, you define the extension on [edit: I should note that Kotest does seem to nudge people toward the Hamcrest-style Failure messagesThe only one that immediately concerned me was the Kotest failure message...
...with no information about the map contents. On the one hand, this is easily fixable. On the other hand, Kotest has been around a while, and no one has fixed it yet. And if the easiest way to produce a failure message is the way that omits the value under test, then I imagine this isn't the only such failure message in Kotest, and authors of custom assertions are likely to fall into the same trap. At the opposite side of the spectrum, we have these Atrium examples. I applaud the inclusion of lots of information, but several lines with information like DocsAssertK and Kotest look pretty reasonable at first glance. Atrium is kind of scary:
But to be fair, the bigger question is what the experience of using these is like in an IDE, since an IDE is (from what I hear) basically a necessity for writing significant Kotlin already. EvolutionI wonder if the biggest concern is going to be how the various libraries are maintained over time. First, of course, we want them simply to be maintained :) The 3 I've been looking at have all been around at least a few years, so that's encouraging. All have one dominant contributor, but it's most extreme with Atrium (vs. AssertK, Kotest). We might also look to current popularity. Based just on GitHub watches/stars/forks, I see Kotest well above AssertK and Atrium. It's worth noting that Kotest offers more than just assertions, so that doesn't mean that Kotest assertions are getting a ton of specific attention, just that the project is (hopefully) less likely to be abandoned. Another thing to watch for is breaking changes. Yes, we have been known to make breaking changes, we see value in making them judiciously, and we have tools to keep up with them. Still, we might not want to build our own extensions on an ecosystem that is changing a lot, since our users might not be in the same position.
I wish people didn't have a method named "containsAll"...given our experience with that method. But AssertK and Kotest both do, and Atrium has a varargs |
Anyway:
So no one should take the following too seriously. But if you have no idea which to pick and you're going to try one first, I'm kind of liking my early impression of AssertK:
AssertK, while probably still a bit in flux itself and arguably lacking the API coverage of Kotest (but that claim seems out of date, as I see assertions for As a more conservative alternative, it sounds like the built-in kotlin.test assertions will get you pretty far, too, with failure messages that likely contain what you need to know but without AssertK's nicer formatting. I'd be happy to hear about others' hands-on experiences, especially if there are features that could translate well to Truth or important features that just can't translate to Truth. |
One thing that's not entirely clear to me is how well the various libraries support collection assertions: AssertK:
Kotest:
Atrium probably offers a lot ("sophisticated contains assertions"), though I noted my worry about complexity. Anyway: Maybe the theory for the |
more assertion libs to compare with: |
I like the |
FYI that's one of the awesome things that truth-generator unlocks for Java 🤗 E.g.: confluentinc/parallel-consumer@0f993dd
|
Hey everyone, I did an analysis a while ago comparing some of the assertion libraries that could be used in Kotlin projects. Browsing on GitHub I was surprised to see that this is exactly what people in this thread are looking for 😄 Here is the repository link. I was not as granular as @cpovirk in some topics, but hope you can find something useful there. |
@cpovirk thanks for the write-up, gives me a chance to see where we can improve Atrium further :)
That's planned (I even started two or even three years ago but don't have enough time for Atrium in the moment unfortunately and as you noted, most contributions are written on my keyboard) => robstoll/atrium#295
Atrium's
Or do you think Atirum did the same mistake? In any case, I am very open to collaborate where it makes sense. Atrium is built up by several modules and it would for instance be possible to re-use the reporting mechanism. |
Hi, @robstoll (and @vlsi, whose username I see here and there pretty often :)). My fear with such methods isn't so much the failures as it is the unintentional successes: If I write I suspect you're right that "toContain" is less likely to be misunderstood than a "toContainAll" method would be: Without the word "all," users are less likely to assume that the values they pass are expected to be "all" the contents. I still wouldn't be surprised to see it misused occasionally, since a user in a hurry may latch onto any varargs "contains" method as "an assertion about the [entire] contents." But I'm speculating; I don't have anything like the very clear data we had from back when Truth had a |
I see your fear and I think it is important to prevent users from such pitfalls. In this particular case I think it is safe to use the name as it has the same semantic as Collection.contains and I believe most developers are familiar with it. |
They have various Kotlin-specific advantages. It would be good to understand what those are. Maybe someday we can provide some of them ourselves (though we haven't followed through on our Kotlin ambitions much yet).
[edit: EventFahrplan/EventFahrplan#141 (comment) was interested in this.]
[edit: One particular thing we should look into is whether those libraries support Kotlin multiplatform (KMP). I've heard that Kotest supports it, and it sounds like Kluent has at least some support.]
The text was updated successfully, but these errors were encountered: