0Pricing
Spring Boot 4 Microservices & REST APIs · Ders

@SpringBootTest ile Entegrasyon Testleri

Uygulamanın tüm bağlamını test edin.

@SpringBootTest ile Entegrasyon Testleri, CoddyKit'te ücretsiz bir Spring Boot 4 Microservices & REST APIs dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Spring Boot 4 Microservices & REST APIs öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

What is an Integration Test

An integration test exercises multiple layers together — controller, service, repository — using a real Spring context.

It catches wiring and configuration problems that unit tests miss.

@SpringBootTest

@SpringBootTest boots the entire application context, loading all beans.

@SpringBootTest
class ApplicationIntegrationTest {
    @Autowired
    UserService userService;

    @Test
    void contextLoads() {
        assertThat(userService).isNotNull();
    }
}

WebEnvironment Modes

Control whether a real server starts with the webEnvironment attribute.

  • MOCK (default) — mock servlet environment
  • RANDOM_PORT — real server on a random port
@SpringBootTest(
    webEnvironment = WebEnvironment.RANDOM_PORT)
class ApiTest { }

Testing with TestRestTemplate

With a real port you can make actual HTTP calls using TestRestTemplate.

@Autowired
TestRestTemplate restTemplate;

@Test
void getsUser() {
    ResponseEntity<User> response =
        restTemplate.getForEntity("/users/1", User.class);
    assertThat(response.getStatusCode())
        .isEqualTo(HttpStatus.OK);
}

WebTestClient

WebTestClient is a fluent client that works for both MVC and WebFlux apps.

@Autowired
WebTestClient webTestClient;

@Test
void getsUser() {
    webTestClient.get().uri("/users/1")
        .exchange()
        .expectStatus().isOk()
        .expectBody()
        .jsonPath("$.name").isEqualTo("Alice");
}

Using a Test Database

By default Spring Boot can replace your datasource with an in-memory H2 database for tests.

@SpringBootTest
@AutoConfigureTestDatabase
class RepositoryIntegrationTest {
    @Autowired UserRepository repository;
}

Test Properties

Override configuration for tests with @TestPropertySource or an application-test.properties profile.

@SpringBootTest
@TestPropertySource(properties = {
    "feature.enabled=false"
})
class FeatureTest { }

Activating Profiles

Use @ActiveProfiles to run with a specific Spring profile.

@SpringBootTest
@ActiveProfiles("test")
class ServiceTest { }

Transactional Rollback

Annotate tests with @Transactional so each test's database changes roll back automatically, keeping tests isolated.

@SpringBootTest
@Transactional
class UserPersistenceTest {
    @Test
    void savesAndRollsBack() {
        repository.save(new User("Alice"));
    }
}

Slicing for Speed

Full @SpringBootTest is slow. Prefer slices like @DataJpaTest or @WebMvcTest when you only need one layer.

@DataJpaTest

@DataJpaTest loads only JPA components and an embedded database — ideal for repository tests.

@DataJpaTest
class UserRepositoryTest {
    @Autowired UserRepository repository;

    @Test
    void findsByName() {
        repository.save(new User("Alice"));
        assertThat(repository.findByName("Alice"))
            .hasSize(1);
    }
}

Quick Check

Test your understanding of integration testing.

Recap

You learned to write integration tests:

  • @SpringBootTest loads the full context
  • RANDOM_PORT + TestRestTemplate/WebTestClient for real HTTP
  • @Transactional rolls back DB changes
  • Use slices for speed

Sıkça Sorulan Sorular

“@SpringBootTest ile Entegrasyon Testleri” dersi ücretsiz mi?

Evet — “@SpringBootTest ile Entegrasyon Testleri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Spring Boot 4 Microservices & REST APIs kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Spring Boot 4 Microservices & REST APIs kursu toplamda 4 dersten oluşur.

“@SpringBootTest ile Entegrasyon Testleri” dersinde ne öğreneceğim?

Uygulamanın tüm bağlamını test edin. Spring Boot 4 Microservices & REST APIs ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Spring Boot 4 Microservices & REST APIs öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Spring Boot 4 Microservices & REST APIs, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.

“@SpringBootTest ile Entegrasyon Testleri” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Spring Boot 4 Microservices & REST APIs dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Spring Boot 4 Microservices & REST APIs dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. JUnit ve Mockito ile Birim Testleri
  2. MockMvc ile Web Katmanı Testleri
  3. @SpringBootTest ile Entegrasyon Testleri
  4. Testcontainers ile Gerçek Bağımlılıklar
← Spring Boot 4 Microservices & REST APIs Sayfasına Dön