naver / fixture-monkey

Let Fixture Monkey generate test instances including edge cases automatically
https://naver.github.io/fixture-monkey
Apache License 2.0
560 stars 89 forks source link

Jpa 연관관계가 있는 엔티티를 생성하려면 어떻게 하면될까요? (해결했습니다.) #982

Closed junho3 closed 4 months ago

junho3 commented 4 months ago

Describe your question

Tell us what kind of problem you are having.

안녕하세요. Fixtures-monkey로 Jpa 연관관계가 있는 엔티티를 생성하고, 영속화를 해보는 중인데요.

// as-is
val asIs = OrderProduct(
    name = name,
    quantity = quantity,
    order = order,
)

// to-be
val toBe = FixtureMonkey.builder()
    .plugin(KotlinPlugin())
    .build()
    .giveMeBuilder<OrderProduct>()
    .set(OrderProduct::order, order) << 이부분
    .sample()

as-is 와 같이 OrderProduct 객체를 생성하던 것을 to-be처럼 변경해봤습니다. 그런데, to-be는 다른 order 객체가 할당되는걸로 보이는데, 방법이 있을까요?

스크린샷 2024-05-31 오후 3 33 48

문의글 올리고 나서 우연히 공식문서에서 해결방법 찾았습니다. 🥲

val asIs = FixtureMonkey.builder()
    .plugin(KotlinPlugin())
    .build()
    .giveMeBuilder<OrderProduct>()
    .set(OrderProduct::order, Values.just(order))
    .sample()