WireMock ile Dış API'leri Test Etme
Harici HTTP hizmetlerine çağrı yapan kodu, ağa erişmek yerine bu hizmetleri WireMock ile sahteleyerek entegrasyon testiyle sınayın.
WireMock ile Dış API'leri Test Etme, CoddyKit'te ücretsiz bir Testing Mastery: JUnit, Mockito & Integration Tests dersidir. Bu, 4 dersinin 4. 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, Testing Mastery: JUnit, Mockito & Integration Tests öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Testing Mastery: JUnit, Mockito & Integration Tests kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
The External Dependency Problem
Integration tests often touch real collaborators, but calling a live third-party API is slow, flaky, and may cost money. WireMock runs a local HTTP server you can program to mimic that API.
What WireMock Provides
WireMock lets you:
- Stub HTTP responses for specific requests
- Simulate delays, errors, and edge cases
- Verify that your code made the expected calls
Starting a WireMock Server
In JUnit you start WireMock on a port (or a random one) before tests run.
WireMockServer server =
new WireMockServer(options().dynamicPort());
server.start();Stubbing a Response
Tell WireMock how to respond to a request using its fluent builder.
server.stubFor(get(urlEqualTo("/users/1"))
.willReturn(aResponse()
.withStatus(200)
.withBody("{\"id\":1}")));Pointing Your Client at WireMock
Configure the code under test to use WireMock's base URL. Using the dynamic port keeps tests isolated.
String baseUrl =
"http://localhost:" + server.port();
UserClient client = new UserClient(baseUrl);Exercising the Code
Now call your client. It hits WireMock, which returns the stubbed payload, and your assertions check the parsed result.
User u = client.fetch(1);
assertEquals(1, u.getId());Simulating Failures
Return a 500 or a malformed body to test your error handling and retries.
server.stubFor(get(urlEqualTo("/users/2"))
.willReturn(aResponse().withStatus(500)));Simulating Latency
Add a fixed delay to verify timeout handling.
server.stubFor(get(anyUrl())
.willReturn(aResponse()
.withFixedDelay(3000)));Verifying Requests
WireMock can assert that your code actually made a call with the right method, path, and headers.
server.verify(getRequestedFor(
urlEqualTo("/users/1")));Cleaning Up
Stop the server after tests, and reset stubs between tests so they stay independent.
server.resetAll();
server.stop();Where It Fits
WireMock sits between unit tests (which mock objects) and full E2E tests (which use real services). It gives realistic HTTP behavior without external dependencies.
Quick Check
What is the main reason to use WireMock in integration tests?
Recap
You learned to test external API calls:
- WireMock runs a local programmable HTTP server
- Stub responses, errors, and delays with its builder
- Point your client at the dynamic port
- Verify requests and reset between tests
Sıkça Sorulan Sorular
“WireMock ile Dış API'leri Test Etme” dersi ücretsiz mi?
Evet — “WireMock ile Dış API'leri Test Etme” 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 Testing Mastery: JUnit, Mockito & Integration Tests kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Testing Mastery: JUnit, Mockito & Integration Tests kursu toplamda 4 dersten oluşur.
“WireMock ile Dış API'leri Test Etme” dersinde ne öğreneceğim?
Harici HTTP hizmetlerine çağrı yapan kodu, ağa erişmek yerine bu hizmetleri WireMock ile sahteleyerek entegrasyon testiyle sınayın. Testing Mastery: JUnit, Mockito & Integration Tests 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.
Testing Mastery: JUnit, Mockito & Integration Tests öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Testing Mastery: JUnit, Mockito & Integration Tests, 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 4. dersidir.
“WireMock ile Dış API'leri Test Etme” 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 Testing Mastery: JUnit, Mockito & Integration Tests dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Testing Mastery: JUnit, Mockito & Integration Tests 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
- Birim ve Bütünleştirme Sınamaları
- Bütünleştirme Sınamalarını Kurma
- Veritabanı Etkileşimlerini Sınama
- WireMock ile Dış API'leri Test Etme