Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
web:framework:spring:tests [2023/12/18 01:31] – [Selenium tests] jcheron | web:framework:spring:tests [2023/12/18 08:45] (Version actuelle) – [Autorisations] jcheron | ||
---|---|---|---|
Ligne 28: | Ligne 28: | ||
< | < | ||
< | < | ||
- | < | + | < |
< | < | ||
</ | </ | ||
Ligne 71: | Ligne 71: | ||
</ | </ | ||
==== Test ==== | ==== Test ==== | ||
+ | |||
+ | Mocking : | ||
+ | * Serveur : <wrap round box> | ||
+ | * Service HelloService : <wrap round box> | ||
Ligne 110: | Ligne 114: | ||
===== Tests d' | ===== Tests d' | ||
+ | |||
+ | Test d' | ||
+ | |||
+ | <sxh java; | ||
+ | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
+ | class HttpRequestTest { | ||
+ | |||
+ | @LocalServerPort | ||
+ | private int port; | ||
+ | |||
+ | @Autowired | ||
+ | private TestRestTemplate restTemplate; | ||
+ | |||
+ | @Test | ||
+ | void greetingShouldReturnDefaultMessage() throws Exception { | ||
+ | assertThat(this.restTemplate.getForObject(" | ||
+ | String.class)).contains(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
==== @SpringBootTest & @AutoConfigureMockMvc ==== | ==== @SpringBootTest & @AutoConfigureMockMvc ==== | ||
+ | |||
+ | Mock du serveur web, remplacé par **MockMvc** : | ||
+ | |||
<sxh java; | <sxh java; | ||
@SpringBootTest | @SpringBootTest | ||
Ligne 152: | Ligne 180: | ||
==== Autorisations ==== | ==== Autorisations ==== | ||
+ | |||
+ | Mocking : | ||
+ | |||
+ | * Serveur web <wrap round box> | ||
+ | * Roles/Users <wrap round box> | ||
<sxh java; | <sxh java; |