SonarQube throws "Replace randomly generated values with fixed ones." for Test methods

440 Views Asked by At

I use random UUID values in my test methods and get "Replace randomly generated values with fixed ones." error after pipeline. I am not sure if giving a fixed UUID value is a good idea. So, how should I create UUID variable properly in my test methods?

@Test
public void test() {
    final UUID uuid = UUID.randomUUID();
    demoService.update(demoRequest, uuid);
}
1

There are 1 best solutions below

11
Andy Aspell-Clark On

First, I would ask what do you need the UUID for? what are you testing? is it a DB PK? are you starting from an empty DB?

if you use a random UUID, how do you retrieve the object to test it later?