νμ€ν μΉπ κ°λ°μ μ§λ§μ π§π½βπ»
β μΈκ³΅μ§λ₯ κ΄μ¬ π€
Categories
-
β£
βΆ COMPUTER_SCIENCE
π: 7 -
β£
βΆ WEB
π: 3 -
β£
βΆ ETC
π: 3-
β
β£
ETCS
π: 10 -
β
β£
SUBBRAIN κ°λ°κΈ°
π: 5 -
β
β
YOS κ°λ°κΈ°
π: 1
-
β
β£
-
β
βΆ AI
π: 9-
β£
AITOOLS
π: 3 -
β£
CV
π: 2 -
β£
DEEP_LEARNING
π: 1 -
β£
DATA_VIS
π: 2 -
β£
GRAPH
π: 1 -
β£
LIGHTWEIGHT
π: 1 -
β£
MATH
π: 1 -
β£
NLP
π: 3 -
β
STRUCTURED_DATA
π: 2
-
β£
Spring5-ν μ€νΈ
Spring5-ν μ€νΈ
_ μ΄λ³΄ μΉ κ°λ°μλ₯Ό μν μ€νλ§ 5 νλ‘κ·Έλλ° μ λ¬Έ _μ μ€νλ§ μΈ μ‘μ μ λ΄μ©μ λ°νμΌλ‘ μ 리ν λ΄μ©μ λλ€.
Spring boot
λ₯Ό μ΄μ©νλ©΄ JUnit
μ μ΄μ©ν ν
μ€ν
μ½λλ₯Ό μμ±ν μ μλ€.
κΈ°λ³Έ ν μ€νΈ νμΌ
src/test/java/Sp5ChapbApplicationTests.java
첫 μ€νλ§ λΆνΈ νλ‘μ νΈ μμνλ©΄ μλμ κ°μ κΈ°λ³Έ ν μ€νΈ μ½λκ° λμ¨λ€.
package sp5chapb;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
@SpringBootTest // JunitμΌλ‘ μ€νλ§ λΆνΈ ν
μ€νΈ μμ
class Sp5ChapbApplicationTests {
@Test // ν
μ€νΈ νλͺ©
void contextLoads() {
// μ무κ²λ μμΌλ©΄ λ¨μ μ€νλ§ μ± μ»¨ν
μ€νΈ λ‘λ
fail("Not yet implemented"); //ν
μ€νΈ μ€ν¨
}
}
Spring suiteμ Spring bootλ₯Ό κ°μ΄ μ¬μ©νλ©΄ λ΄μ₯λ JUnit
μ ν΅ν΄ Run As
-> Junit Test
λ‘ ν
μ€νΈ κ°λ₯νλ€.
μ΄ν μ€ν¨μ μ±κ³΅ κ°―μλ₯Ό λΉκ΅νκ³ μ€ν¨ μμΈμ μΆλ ₯ν΄μ€λ€.
μ€νλ§ MVC ν μ€νΈ μ½λ
package tacos;
import static org.hamcrest.CoreMatchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.web.servlet.MockMvc;
@WebMvcTest(HomeController.class) // ν
μ€νΈν 컨νΈλ‘€λ¬ μ§μ
class HomeControllerTest {
@Autowired
private MockMvc mockMvc; // μ€μ μλ² λμ κ°μ§ μμ²μ λ³΄λΌ λΉ κ°μ²΄ μ£Όμ
@Test // νλμ ν
μ€νΈ νλͺ©μ μ μ
public void testHomePage() throws Exception {
mockMvc.perform(get("/")) // μμ²μ μμ±
.andExpect(status().isOk()) // status 체ν¬
.andExpect(view().name("home")) // λ·° 체ν¬
.andExpect(content().string(containsString("Welcome to..."))); // νμ΄μ§ λ΄λΆμ λ΄μ© κ²μ
}
}
@WebMvcTest
λ μ€νλ§ MVCλ₯Ό ν μ€νΈνκΈ° μν μ€νλ§ λΆνΈμ μ 곡 μ΄λ Έν μ΄μ μ΄λ€.
_articles/web/backend/Spring/Spring5-ν μ€νΈ.md