web:framework:spring:tests

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

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] jcheronweb:framework:spring:tests [2023/12/18 08:45] (Version actuelle) – [Autorisations] jcheron
Ligne 28: Ligne 28:
  <groupId>io.github.bonigarcia</groupId>  <groupId>io.github.bonigarcia</groupId>
  <artifactId>webdrivermanager</artifactId>  <artifactId>webdrivermanager</artifactId>
- <version>5.3.1</version>+ <version>5.6.2</version>
  <scope>test</scope>  <scope>test</scope>
  </dependency>  </dependency>
Ligne 71: Ligne 71:
 </sxh> </sxh>
 ==== Test ==== ==== Test ====
 +
 +Mocking :
 +  * Serveur : <wrap round box>@MockMvc</wrap>
 +  * Service HelloService : <wrap round box>@MockBean</wrap>
  
  
Ligne 110: Ligne 114:
  
 ===== Tests d'intégration ===== ===== Tests d'intégration =====
 +
 +Test d'intégration avec lancement du serveur sur Random port (pour éviter les conflits).
 +
 +<sxh java;title:HelloControllerTest.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("http://127.0.0.1:" + port + "/",
 + String.class)).contains("Hello World!");
 + }
 +}
 +</sxh>
 +
 ==== @SpringBootTest & @AutoConfigureMockMvc ==== ==== @SpringBootTest & @AutoConfigureMockMvc ====
 +
 +Mock du serveur web, remplacé par **MockMvc** :
 +
 <sxh java;title:HelloControllerTest.java> <sxh java;title:HelloControllerTest.java>
 @SpringBootTest @SpringBootTest
Ligne 152: Ligne 180:
  
 ==== Autorisations ==== ==== Autorisations ====
 +
 +Mocking :
 +
 +  * Serveur web <wrap round box>MockMvc</wrap>
 +  * Roles/Users <wrap round box>@WithMockUser</wrap> <wrap round box>@WithAnonymousUser</wrap>
  
 <sxh java;title:SecureApplicationTests.java> <sxh java;title:SecureApplicationTests.java>
  • web/framework/spring/tests.1702859465.txt.gz
  • Dernière modification : il y a 16 mois
  • de jcheron