gpt4 book ai didi

java - 找不到 Java 包 powermock.api.mockito

转载 作者:行者123 更新时间:2023-12-01 10:34:27 26 4
gpt4 key购买 nike

我正在尝试让 Power Mockito 在我的 java 测试中工作。我一生都无法找到它。我尝试在 pom 文件中插入依赖项,重建项目并运行测试,但仍然找不到它。有什么想法为什么它找不到这个吗?

这是我的 MemberServiceTest.java 文件中的内容:

package com.cerner.revenuecycle.vbr.services;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.hibernate.SessionFactory;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.powermock.api.mockito.PowerMockito; //***** cant find *****
import org.powermock.core.classloader.annotations.PrepareForTest; //**** cant find ****
import org.powermock.modules.junit4.PowerMockRunner; //***** cant find ****

@RunWith(MockitoJUnitRunner.class)
public class MemberServiceTest {

@InjectMocks
MemberService memberService;

@Mock
MemberHibernate memberHibernate;

@Mock
CaseHelper caseHelper;

@Test
public void testGetCaseNumber() {

SessionFactory testSessionFactory = HibernateUtil.newTestSessionFactory();
PowerMockito.mockStatic(HibernateUtil.class); //this doesnt work now


PowerMockito.when(HibernateUtil.getSessionFactory()).thenReturn(testSessionFactory); //this doesnt work now
Case case1 = new Case();
Case case2 = new Case();
case1.setTenantId("1");
case2.setTenantId("2");

String caseNum1 = caseHelper.getNextCaseNumberFromDatabase(case1.getTenantId());
String caseNum2 = caseHelper.getNextCaseNumberFromDatabase(case2.getTenantId());

assertEquals(caseNum1, caseNum2);

}
}

在我的 pom.xml 文件中,如您所见,我已将mockito 和 powermock 依赖项放在那里:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.cerner.revenuecycle.vbr</groupId>
<artifactId>vbr-services-integration</artifactId>
<packaging>jar</packaging>

<parent>
<groupId>com.cerner.revenuecycle.vbr</groupId>
<artifactId>vbr-services-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<name>vbr-services-integration</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.17</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>1.0-beta-7</version>
</dependency>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>

知道为什么找不到 powermockito 库吗?

最佳答案

我不知道你是否尝试过,但现在就开始吧。

尝试强制更新依赖项“mvn clean install -U”,并尝试检查 jar 是否在您的 m2 中。文件夹

关于java - 找不到 Java 包 powermock.api.mockito,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34864662/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com