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:
If you use .toUUID() you can get the same result like this:
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:
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().