Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 通过IntelliJ运行pact jvm提供程序测试_Java_Intellij Idea_Junit_Pact - Fatal编程技术网

Java 通过IntelliJ运行pact jvm提供程序测试

Java 通过IntelliJ运行pact jvm提供程序测试,java,intellij-idea,junit,pact,Java,Intellij Idea,Junit,Pact,我正在尝试使用IntelliJ IDE作为我的IDE 我正在测试提供的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.p

我正在尝试使用IntelliJ IDE作为我的IDE

我正在测试提供的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");
    }
}
但当我尝试运行测试(运行->运行ContractTest)时,就好像根本没有运行测试:

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

进程已完成,退出代码为0

我不确定这是否与我如何在IntelliJ中运行测试有关,或者我在pact jvm提供程序“runner”中遗漏了一些内容

感谢您对本主题的帮助


谢谢

看一看,特别是,有一个已经预定义的pactproviderrule。另外,看起来您正在尝试使用JUnit5运行测试,而JUnit5目前不受支持。将JUnit设置为版本4,然后尝试重新运行测试。