धन्यवाद @LiorH: इस नियम के
प्रयोग कुछ इस तरह दिखेगा।
ड्रॉपविज़ार्ड-0.6.2 में DropwizardServiceRule का उपयोग करके एक पूर्ण परीक्षण कक्षा है।
पहले परीक्षण के लिए एक सेवा कॉन्फ़िगरेशन बनाएं: testing-server.yml
और इसे टेस्ट के क्लास पथ (उदा। src\test\resources
) में रखें।
class TheServiceTest {
@ClassRule
public static DropwizardServiceRule RULE = new DropwizardServiceRule<MyConfiguration>(TheService.class,
Resources.getResource("testing-server.yml").getPath());
@Test
public void
dropwizard_gets_configured_correctly() throws Exception {
Client client = new Client();
ClientResponse response = client.resource(
String.format("http://localhost:%d/request", RULE.getLocalPort()))
.get(ClientResponse.class);
assertThat(response.getStatus(), is(200));
}
}
:
http:
port: 7000
adminPort: 7001
एक साधारण परीक्षण वर्ग कि अगर कोई स्थान "/ अनुरोध" पर एक संसाधन है की जाँच करता है इस तरह दिखता है: इस तरह आप परीक्षण सेवा का उपयोग करने के लिए विभिन्न बंदरगाहों सेट कर सकते हैं
यदि आपने नहीं पता कि कौन सा कार्यान्वयन चुनना है तो मैंने आयात भी जोड़ा है।
import com.google.common.io.Resources;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.yammer.dropwizard.testing.junit.DropwizardServiceRule;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TestRule;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
परीक्षण के अंत में, सर्वर इच्छा बंद शान से, आप इसके बारे में चिंता करने की जरूरत नहीं है इसलिए।
स्रोत
2014-04-04 14:48:56
क्या आप मुझे कुछ नमूना कोड पर इंगित कर सकते हैं? मुझे समझ में नहीं आता कि इसके बारे में कैसे जाना है। – Neo