I am trying to use random-beans library to be able to crear my test beans faster. The dependency used is (https://github.com/benas/random-beans):
<dependency>
<groupId>io.github.benas</groupId>
<artifactId>random-beans</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>
Beans are:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
private String surname;
private Integer age;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<Book> books;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String title;
private String description;
private Integer pages;
This is my test code (limiting collectionsize to 1):
EnhancedRandom random = EnhancedRandomBuilder.aNewEnhancedRandomBuilder()
.charset(forName("UTF-8"))
.stringLengthRange(5, 50)
.collectionSizeRange(1, 1)
.scanClasspathForConcreteTypes(true)
.overrideDefaultInitialization(false)
.build();
User user = random.random(User.class);
assertThat(user.getBooks()).hasSize(1);
My test fail in this assert:
assertThat(user.getBooks()).hasSize(1);
Why books size is no the same that i have configured with my random object?
Aucun commentaire:
Enregistrer un commentaire