0

我非常尝试使用 IntelliJ IDEA 作为我的 IDE的pact-jvm-provider-junit 。

我正在测试提供的 ContractTest 示例:

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.ClassRule;

import au.com.dius.pact.provider.junit.State;
import au.com.dius.pact.provider.junit.Provider;
import au.com.dius.pact.provider.junit.target.TestTarget;
import au.com.dius.pact.provider.junit.target.Target;
import au.com.dius.pact.provider.junit.target.HttpTarget;
import au.com.dius.pact.provider.junit.TargetRequestFilter;

import org.apache.http.HttpRequest;


import au.com.dius.pact.provider.junit.PactRunner;
import au.com.dius.pact.provider.junit.loader.PactFolder;
import au.com.dius.pact.provider.junit.loader.PactUrl;
import au.com.dius.pact.provider.junit.VerificationReports;

import com.github.restdriver.clientdriver.ClientDriverRule;

import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;

import org.slf4j.Logger;

import static com.github.restdriver.clientdriver.RestClientDriver.giveEmptyResponse;
import static com.github.restdriver.clientdriver.RestClientDriver.onRequestTo;



@RunWith(PactRunner.class) // Say JUnit to run tests with custom Runner
@Provider("uicc_repository") // Set up name of tested provider
//@PactFolder("rs") // Point where to find pacts (See also section Pacts source in documentation)
@PactUrl(urls = {"file:///C:/IdeaProjects/src/pack-test-provider/resources/test_consumer-test_provider.json"}) // Point where to find pacts (See also section Pacts source in documentation)
@VerificationReports(value = {"markdown","json"}, reportDir = "C:/IdeaProjects/src/pack-test-provider/resources")

public class ContractTest {


    // NOTE: this is just an example of embedded service that listens to requests, you should start here real service
    @ClassRule //Rule will be applied once: before/after whole contract test suite
    public static final ClientDriverRule embeddedService = new ClientDriverRule(6060);
    private static final Logger LOGGER = LoggerFactory.getLogger(ContractTest.class);

    @BeforeClass //Method will be run once: before whole contract test suite
    public static void setUpService() {
        //Run DB, create schema
        //Run service
        //...
    }

    @Before //Method will be run before each test of interaction
    public void before() {
        // Rest data
        // Mock dependent service responses
        // ...
        embeddedService.addExpectation(
                onRequestTo("/data"), giveEmptyResponse()
        );
    }

    @TestTarget // Annotation denotes Target that will be used for tests
    public final Target target = new HttpTarget(6060); // Out-of-the-box implementation of Target (for more information take a look at Test Target section)

    @State("default") // Method will be run before testing interactions that require "default" or "no-data" state
    public void toDefaultState() {
        // Prepare service before interaction that require "default" state
        // ...
        System.out.println("Now service in default state");
        LOGGER.info("Now service in default state");
    }
}

但是当我尝试运行测试(Run -> Run ContractTest)时,就好像测试根本没有运行:

2017 年 3 月 15 日下午 3:24:00 org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines 信息:发现的测试引擎 ID:[junit-jupiter,junit-vintage] 2017 年 3 月 15 日下午 3:24:01 junit.vintage.engine.execution.TestRun lookupTestDescriptor 警告:运行器 au.com.dius.pact.provider.junit.PactRunner 类 rs.ContractTest 报告了未知事件描述:rs.ContractTest。它将被忽略。

进程以退出代码 0 结束

在此处输入图像描述

我不确定这是否与我在 IntelliJ 中运行测试的方式有关,或者我在 pact-jvm-provider“跑步者”中遗漏了一些东西。

感谢有关此主题的任何帮助。

谢谢!

4

0 回答 0