Java Powermock避免运行要模拟的类的PrepareForTest

Java Powermock避免运行要模拟的类的PrepareForTest,java,rest,testing,powermock,Java,Rest,Testing,Powermock,我需要您帮助进行PowerMock和一些REST测试 我想测试REST-GET-all,它通过不同的包从数据库返回数据。因此,REST方法调用executionService.getData @Path("interface/more/path/") public class RestConnection { [..] @GET @Path("path/{ID}/") @Produces(MediaType.APPLICATION_JSON) publi

我需要您帮助进行PowerMock和一些REST测试

我想测试REST-GET-all,它通过不同的包从数据库返回数据。因此,REST方法调用executionService.getData

@Path("interface/more/path/") 
public class RestConnection {
    [..]
    @GET
    @Path("path/{ID}/")
    @Produces(MediaType.APPLICATION_JSON)
    public Response showDetails(@PathParam("ID") int ID) {
         if (something == 0) {
         LinkedList<Integer> scenarioIDs = executionService.getData();
         [..]
错误和错误

java.net.ConnectException: Connection refused
错误。此外,PowerMock似乎执行了试图连接到数据库的原始getData方法。这也失败了。你能帮我吗


谢谢

在MockingHanks Vihar的末尾添加Powermock.Replayal,这并不能解决问题:遇到相同的问题。。。你不知怎么把它修好了吗?
@PowerMockIgnore({"javax.net.ssl.*","java.sql.*","com.mysql.jdbc.*"})
@RunWith(PowerMockRunner.class)
@PrepareForTest(ExecutionService.class)
public class RestConnectionTest {

    private ExecutionService executionService = new ExecutionService();

    @Before
    public void setUp() {
        ExecutionService executionService = PowerMock.createPartialMock(ExecutionService.class,
                "getData");
    }

    @Test
    public void testGetScenarios() {
        suppress(constructor(Connection.class));
        String getUrl = "/interface/more/path/path/0/";

        try {
            //PowerMock.mockStatic(ExecutionService.class);
           // PowerMock.replay(ExecutionService.class);
            PowerMock.expectPrivate(executionService, "getData").andAnswer(new IAnswer<LinkedList>() {
                @Override
                public LinkedList answer() throws Throwable {
                    LinkedList ll = new LinkedList();
                    ll.add(1);
                    ll.add(2);
                    ll.add(3);
                    return (ll);
                }
            });
            //PowerMock.verify(ExecutionService.class);

        } catch (Exception e) {
            e.printStackTrace();
        }

        get(getUrl).
                then().
                assertThat().
                body(
                        matchesJsonSchemaInClasspath("json/schema.json")

               );

    }
IllegalStateException - no last call on a mock available
java.net.ConnectException: Connection refused