
These may be default values that you can modify or values calculated using functions. For instance, it would probably make sense to generate a random date instead of the current one, as we could be in a particular case if the code has conditions based on the current date.When you expand a live template abbreviation, its variables either appear as input fields where you can type values or are replaced with values. Thanks to PhpStorm allowing us to execute Groovy code, we can probably think of other ideas and save more time.

In the line for the variable named uuid, add the expression groovyScript("UUID.randomUUID().toString()") and select Skip if defined.In the template text field, enter '$uuid$'$END$.This is what we’ll type to expand the template. In the abbreviation field, enter $uuid$.Generating a UUID is slightly different because PhpStorm doesn’t provide a function to create UUIDs directly, but it, fortunately, allows to run Groovy scripts. Save and close the settings with the Ok button.Click Define below the ⚠️ No applicable contexts.In the line for the variable named date, add the expression date("yyyy-MM-dd'T'HH:mm:ss.SSSz") and select Skip if defined.In the template text field, enter '$date$'$END$.In the abbreviation field, enter $date$.Click on the Add button, + on the right side, and select Live template.In PhpStorm settings, go to Editor > Live Templates.This is what we’ll use.įor generating the current date, we can use the date expression provided by PhpStorm and bind it to a variable. What’s even more remarkable is that they can evaluate expressions when the abbreviation is expanded. Live templates are templates that we can expand by typing an abbreviation and triggering the autocomplete. PhpStorm, and probably all IntelliJ IDEs, allow creating Live templates. Even if typing a date is not as painful, we can gain some time here too. While it’s possible to generate UUIDs using external tools, there is room for improvement if you want to do everything directly in PhpStorm. Two of the most common are dates and UUIDs. When creating this type of test, we want to avoid moving or random values. It’s far easier to fix inputs once and for all. In this kind of test, we feed some input to the system under test and look at the outputs, ensuring that they stay the same test run after test run. One way to introduce some safety net before messing around with the code is to add characterization tests.

Generating dates and UUIDs easily in PhpStorm
