这是可能的,这是我的JUnit测试,做它(ParticipantsService
使用假死客户端)
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureStubRunner(ids = {"com.ryanjbaxter.spring.cloud:ocr-participants:+:stubs"}, workOffline = true)
@DirtiesContext
@ActiveProfiles("test")
public class OcrRacesApplicationTestsBase {
@Autowired
protected ParticipantsService participantsService;
private List<Participant> participants = new ArrayList<>();
//Hack to work around https://github.com/spring-cloud/spring-cloud-commons/issues/156
static {
System.setProperty("eureka.client.enabled", "false");
System.setProperty("spring.cloud.config.failFast", "false");
}
@Before
public void setup() {
this.participants = new ArrayList<>();
this.participants.add(new Participant("Ryan", "Baxter", "MA", "S", Arrays.asList("123", "456")));
this.participants.add(new Participant("Stephanie", "Baxter", "MA", "S", Arrays.asList("456")));
}
@After
public void tearDown() {
this.participants = new ArrayList<>();
}
@Test
public void contextLoads() {
List<Participant> participantList = participantsService.getAllParticipants();
assertEquals(participants, participantList);
}
}
据我以前不工作。我也尝试过。我更新了这个问题。你可以看一下 – blackOcean
你不需要使用Eureka或配置服务器来使合同工作。基于它无法找到与之相匹配的合同这一事实,似乎请求发送与您的合同之间可能存在差异。你可能会发布合同和请求被发送? –
更新:我认为,从Dalston开始,这已经修复了! –