You are currently viewing .toUUID(): A tiny kotlin/jvm library for generating deterministic UUIDs for automated testing

.toUUID(): A tiny kotlin/jvm library for generating deterministic UUIDs for automated testing

Let’s rip off the bandage: UUIDs is a pain to work with within the context of automated testing.

  • Creating UUIDs look ugly
  • Creating UUIDs takes up a lot of space
  • Creating UUIDs decrease readability.

This might all be minor gripes I have, but I like my tests to be short and clean.

The most common way to generate a human-readable UUID is doing the following:

UUID.fromString("00000000-0000-0000-0000-000000000001") 

If you use .toUUID() you can get the same result like this:

1.toUUID() 

There’s also a few more bells and whistles like generating UUIDs based on a collection, varargs, range of integers or even in a sequence.

If you find yourself having to deal with UUIDs in automated tests, or you want to generate a set of simple UUIDs quickly, then .toUUID() might be up your alley:

https://github.com/atomfinger/toUUID

This post was also posted on r/Java a few days ago. If you find yourself sharing some of the same thoughts and opinions expressed in that thread, do head over to the writeup I did in response to it, which hopefully does a better job explaining the value of .toUUID().

submitted by /u/_Atomfinger_
[link] [comments]