-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π 3λ¨κ³ - ν μ€νΈλ₯Ό ν΅ν μ½λ λ³΄νΈ #825
base: sumiini
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν
μ€νΈ μ½λ μμ± λ무 μν΄μ£Όμ
¨μ΅λλ€ π
λͺκ°μ§ μκ°κ±°λ¦¬λ₯Ό λ¨κ²¨λμλλ° νμΈ λΆνλ립λλ€.
μ§λ¬Έμ΄ μλ€λ©΄ νΈνκ² DM μ£ΌμΈμ π
@Test | ||
@Transactional | ||
void create() { | ||
//given |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given / when / then μ μ£ΌμμΌλ‘ νκΈ°νκΈ° λ³΄λ¨ κ³΅λ°± λΌμΈμ ν΅ν΄ μΆ©λΆν ννν μ μμκ² κ°μ΅λλ€ π
|
||
@DisplayName(value = "λ©λ΄ κ·Έλ£Ή μμ± μ κ·Έλ£Ή λͺ μ΄ nullμΌ κ²½μ° IllegalArgumentException μμΈ μ²λ¦¬λ₯Ό νλ€.") | ||
@Test | ||
@Transactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@transactional μ΄λ Έν μ΄μ μ΄ μ΄λ€ μν μ νκ³ μμκΉμ π
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λͺ¨λ μ μμ μΌλ‘ μ€νλλ©΄ μ μμ μΌλ‘ μ€νλλ©΄ 컀λ°λκ³ , μ€κ°μ μμΈκ° λ°μνλ©΄ λ‘€λ°±ν΄μ£Όλ μν μ ν©λλ€.
μλ ν createλΌλ λ©μλλ₯Ό νΈλμμ
μΌλ‘ λͺ
μν κ²μ
λλ€.
λ©λ΄ κ·Έλ£Ή μμ±μ μμΈκ° λ°μνλ©΄, λ©λ΄ κ·Έλ£Ήμ DBμ μ μ₯νμ§ μλλ‘ νλ μν μ ν©λλ€.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpringBootTest + @transactional μ΄λ
Έν
μ΄μ
μ μν μ ν
μ€νΈ μ½λκ° μ μμ μΌλ‘ μ€νλμ΄ μ»€λ°μ΄ λμμλ λ‘€λ°±μ νλ μν μ ν©λλ€.
νμ¬ μμ±ν΄μ£Όμ ν
μ€νΈ μ½λλ μ€ν¨λ₯Ό κ²μ¦νλ ν
μ€νΈ μ½λμ΄κΈ° λλ¬Έμ λͺ
μνμ§ μμλ λ κ² κ°μμ !
String name = "νλ§λ¦¬λ©λ΄"; | ||
MenuGroup request = new MenuGroup(); | ||
request.setName(name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μμ£Ό μ¬μ©νλ ν
μ€νΈ κ°μ²΄λ₯Ό TestFixtureλ‘ μ μνμ¬ κ°λ
μ±κ³Ό μ¬μ¬μ©μ±μ λμΌμ μμ΅λλ€ π
μ΄λ² λ―Έμ
μ μ§ννλ©° TestFixtureμ λν΄ κ²½νν΄λ³΄λκ²μ κΆμ₯ λλ €μ !
https://velog.io/@langoustine/Test-Fixture
.isThrownBy(() -> menuGroupService.create(request)); | ||
} | ||
|
||
@DisplayName(value = "λ©λ΄ κ·Έλ£Ή μμ± μ κ·Έλ£Ή λͺ μ΄ λΉ κ°μΌ κ²½μ° IllegalArgumentException μμΈ μ²λ¦¬λ₯Ό νλ€.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Junitμ ν
μ€νΈλ₯Ό μμ±νκΈ° μν λ€μν κΈ°λ₯μ μ 곡ν©λλ€.
@NullAndEmptySourceμ κ°μ ParameterizedTestμ λν΄ νμ΅ν΄λ³΄μΈμ π
https://gmlwjd9405.github.io/2019/11/27/junit5-guide-parameterized-test.html
import java.util.NoSuchElementException; | ||
import java.util.UUID; | ||
|
||
@SpringBootTest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpringBootTestλ₯Ό νμ©ν ν΅ν© ν μ€νΈλ₯Ό μμ±νλκ²λ μ’μ§λ§ Mockingμ νμ©ν λ¨μ ν μ€νΈ μμ±λ²μ λν΄μλ κ²½νν΄λ³΄λκ²μ κΆμ₯ λ립λλ€ π
|
||
@DisplayName("λ©λ΄ μμ± μ λ©λ΄ κ°κ²©μ΄ null μ΄λ©΄ IllegalArgumentException μμΈ μ²λ¦¬λ₯Ό νλ€.") | ||
@Test | ||
void canNotCreateMenuIfMenuPriceIsNull() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν μ€νΈ μ½λμν¨μλͺ μ μ§λκ²μ λν΄ μ΄λ €μμ κ²ͺμΌμ ¨λ€κ³ λ¨κ²¨μ£Όμ ¨λλ° κ°μΈμ μΌλ‘ ν μ€νΈ μ½λλ₯Ό μμ±ν λ κ°λ μ±μ μν΄ ν¨μλͺ μ νκΈλ‘ μ§κΈ°λ ν©λλ€ π
void canNotCreateMenuIfMenuPriceIsNull() { | |
void `λ©λ΄μμ±_μ€ν¨_κ°κ²©_Null`() { |
Assertions.assertThat(result).extracting(Menu::getId).containsExactly(menu.getId()); | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νμΌμ λ§μ§λ§μ new line μΌλ‘ λλ΄λκ²μ κΆμ₯ λ립λλ€ π
https://stackoverflow.com/questions/729692/why-should-text-files-end-with-a-newline
intellijλ₯Ό μ¬μ©νκ³ κ³μλ€λ©΄ Setting -> Editor -> General οΏ½μμΒ Ensure every saved file ends with a line break μ μΌμ£Όμλ©΄ λ©λλ€ π
|
||
@SpringBootTest | ||
@Transactional | ||
class OrderServiceTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
κΌΌκΌΌν ν
μ€νΈ μ½λ μμ± π
μ£Όλ¬Έ μ νμ λ°λΌ λ¬λΌμ§λ ν
μ€νΈ μΌμ΄μ€κ° μμ΅λλ€.
@nested λ₯Ό νμ©νμ¬ μ£Όλ¬Έ μ νμ λ°λ₯Έ μΌμ€νΈ μΌμ΄μ€λ₯Ό λΆλ¦¬ν΄λ³΄λκ²λ μ’μκ² κ°μ΅λλ€ π
https://www.baeldung.com/junit-5-nested-test-classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ£Όλ¬Έκ³Ό κ΄λ ¨λ ν
μ€νΈ μ½λκ° λΆμ‘±νκ² κ°μ΅λλ€.
λ°°λ¬ μ£Όλ¬Έ / ν¬μ₯ μ£Όλ¬Έ / 맀μ₯ μμ¬ μ£Όλ¬Έ κ³Ό κ°μ΄ μ νλ³λ‘ μ μν΄μ£Όμ μꡬμ¬νμ κΈ°λ°μΌλ‘ μ‘°κΈλ μμΈνκ² ν
μ€νΈ μ½λλ₯Ό μμ±ν΄λ³΄μΈμ π
μμ±ν΄μ£Όμ μꡬμ¬ν λ¬Έμκ° λͺ¨λ ν
μ€νΈ μ½λμ λ
Ήμμ Έ μλ‘μ΄ κ°λ°μκ° νλ‘μ νΈμ μ°Έμ¬μ ν
μ€νΈ μ½λλ§μΌλ‘ μꡬμ¬νμ λΆμν μ μμ μ λκ° λλ©΄ μ’μκ² κ°μμ π
리뷰 λ΄μ©μ λ°μνμ¬ μ 체 ν μ€νΈ μ½λλ₯Ό μμ νμμ΅λλ€. @nested, Test Fixture, @ParameterizedTestλ₯Ό μ κ·Ή νμ©νμ¬ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
νΌλλ°± λ°μ μν΄μ£Όμ
¨μ΅λλ€ π
μ£Όλ¬Έ μλΉμ€μ λν ν
μ€νΈ μ½λ μμ±μ΄ λΆμ‘±νκ² κ°μ 보μ μμ² λ릴κ²μ π
μΆν μ§νλ λ―Έμ
μμ κΈ°μ‘΄μ μμ±λ ν
μ€νΈ μ½λλ₯Ό νμ©ν μ μκΈ° λλ¬Έμ μ‘°κΈλ§ λ νλ΄μ£ΌμκΈΈ λ°λλλ€ !
|
||
@SpringBootTest | ||
@Transactional | ||
class OrderServiceTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ£Όλ¬Έκ³Ό κ΄λ ¨λ ν
μ€νΈ μ½λκ° λΆμ‘±νκ² κ°μ΅λλ€.
λ°°λ¬ μ£Όλ¬Έ / ν¬μ₯ μ£Όλ¬Έ / 맀μ₯ μμ¬ μ£Όλ¬Έ κ³Ό κ°μ΄ μ νλ³λ‘ μ μν΄μ£Όμ μꡬμ¬νμ κΈ°λ°μΌλ‘ μ‘°κΈλ μμΈνκ² ν
μ€νΈ μ½λλ₯Ό μμ±ν΄λ³΄μΈμ π
μμ±ν΄μ£Όμ μꡬμ¬ν λ¬Έμκ° λͺ¨λ ν
μ€νΈ μ½λμ λ
Ήμμ Έ μλ‘μ΄ κ°λ°μκ° νλ‘μ νΈμ μ°Έμ¬μ ν
μ€νΈ μ½λλ§μΌλ‘ μꡬμ¬νμ λΆμν μ μμ μ λκ° λλ©΄ μ’μκ² κ°μμ π
|
||
@DisplayName(value = "λ©λ΄ κ·Έλ£Ή μμ± μ κ·Έλ£Ή λͺ μ΄ nullμΌ κ²½μ° IllegalArgumentException μμΈ μ²λ¦¬λ₯Ό νλ€.") | ||
@Test | ||
@Transactional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SpringBootTest + @transactional μ΄λ
Έν
μ΄μ
μ μν μ ν
μ€νΈ μ½λκ° μ μμ μΌλ‘ μ€νλμ΄ μ»€λ°μ΄ λμμλ λ‘€λ°±μ νλ μν μ ν©λλ€.
νμ¬ μμ±ν΄μ£Όμ ν
μ€νΈ μ½λλ μ€ν¨λ₯Ό κ²μ¦νλ ν
μ€νΈ μ½λμ΄κΈ° λλ¬Έμ λͺ
μνμ§ μμλ λ κ² κ°μμ !
μλ νμΈμ. π
μλΉμ€λ³λ‘ μ μ μΌμ΄μ€, μμΈ κ²μ¦ μΌμ΄μ€ ꡬλΆνμμ΅λλ€.
νλ©΄μ μ΄λ €μ λ λΆλΆμ ν μ€νΈ μ½λμ ν¨μ λͺ μ μ§λ κ²μ΄μμ΅λλ€.
μ΄ λΆλΆμμ λ§μ μκ°μ ν μ νμμ΅λλ€.
μ΄λ²μ κ³κΈ°λ‘ SpringBootTest λ₯Ό λ§μ΄ μ°μ΅νμμ΅λλ€.
μ΄ν μκ°μ΄ λλ€λ©΄, @ExtendWith(MockitoExtension.class) λ¨μ ν μ€νΈλ μΆκ°λ‘ ꡬννμ¬
λ§μ΄ μ°μ΅νλ €ν©λλ€ !