-
2 votesanswersviews
为什么spring会尝试将依赖项注入mock对象?
我对Mockito很新,并有一个问题 . 我正在为我的应用程序使用Spring的依赖注入并尝试测试组件 . 我有这样的测试: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(// @formatter:off loader = SpringockitoAnnotatedContextLoader.class, ... -
1 votesanswersviews
将mockito-mocked bean注入Spring Boot bean以测试仍然加载依赖项
这是我的测试类: @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes={AseCalculatorApplicationImplTestConfig.class}) public class AseCalculatorApplicationImplTest { @Autowired AseCa... -
0 votesanswersviews
Spring Boot版本从1.5.8更改为2.0.0
在尝试迁移到spring boot 2.0版时,我在尝试运行Junits时遇到了以下问题 . 相同的单元测试用于 spring 启动版本1.5.8,但在更改版本后,它们开始失败 . 以下是该问题的堆栈跟踪 . 能不能让我知道同样的根本原因是什么? 应用程序运行失败java.lang.IllegalStateException:org.springframework.boot.autoconfig... -
2 votesanswersviews
@InjectMocks和非模拟对象(Spring Data Repositories)
有没有办法用@InjectMocks注入非模拟对象? 我的安装程序有一个UserSignupService,它依赖于MailService和UserRepository(一个Spring Data Repository) . 我有一个单元测试创建了一个MailService的 Spy ,我用@InjectMocks注释了UserSignupService . 遗憾的是,这不会将UserReposi... -
1 votesanswersviews
在Spring启动应用程序的Spring休息中使用MockMVC测试put方法失败
我正试图在Spring启动应用程序的Spring休息中使用MockMVC来测试我的其余控制器类的put方法 . 测试总是失败给我这个错误 java.lang.AssertionError: Status expected:<200> but was:<400> 下面是其他控制器类 package com.store.rest.controller; import java... -
1 votesanswersviews
使用Spring MVC和Mockito从MockMvc Test中没有JSON内容(来自null)
有一个代码库,它使用SpringMVC 4.0.3.RELEASE进行Restful Web Services . Codebase包含一个功能齐全的Restful Web服务,我可以使用postman和curl验证工作 . 但是,当尝试使用MockMvc为特定的Restful Web Service编写单元测试时,我试图从单元测试中获取JSON内容时被阻止 . 我想知道它是配置问题还是我没有正确... -
-2 votesanswersviews
junit - mockito - 例外
我是JUnit的新手 . 我必须测试一个方法调用必须抛出异常并进入catch块的方法 . 我需要使用JUnit测试此流程 . 当我尝试 Mockito.when(method).thenThrow() 时,它不会抛出异常,并且流不会进入catch块 . 我的课程要测试: public String exceptionMethod() { String return = null; Clas... -
5 votesanswersviews
使用PowerMock在Kotlin中模拟包级功能
我在Kotlin中有一个包含一些包级函数的文件 . //Logger.kt fun info(tag : String, message : String){ ... } fun error{....} 我正在测试一个调用这个kotlin文件函数的类的函数,我想嘲笑它们 . 我知道包级函数就像Java中的静态方法一样,所以我一直在考虑使用PowerMock . //MyClass: Clas... -
1 votesanswersviews
如何模拟对象方法调用方法中的那个?
所以这里是我想要创建测试的类和方法: public class RequestController { private GetAllInter getAnalytics;//This is an interface @RequestMapping(value ="",method=RequestMethod.GET) public String getAllAnaly... -
0 votesanswersviews
单元测试使用Mockito | Android调用私有回调的方法
我试图在Android中对以下方法进行单元测试: @Override public void onTryAgain() { mView.showLoading(); mGetLoginSsoUseCase.execute( getLoginSsoLink(), new GetSsoLinkUseCase.Params(mUrl));... -
2 votesanswersviews
单元测试静态方法
我正在尝试为此方法解密一个测试用例 . private static Codec codec; static { try { codec = new Codec(encryptionType, encryptionKey, false, true, false); } catch (CodecException e) { ... -
1 votesanswersviews
如何在测试期间修改静态私有字段?
我的项目使用 JUnit , Mockito , PowerMockito 来创建单元测试 . 代码如下: public class FirstController { public void doSomething() { ServiceExecutor.execute(); } } public class ServiceExecutor { pri... -
0 votesanswersviews
单元测试Spring MockMVC执行Post:JSON路径“$ .email”没有值
在此方法测试中,我必须对/ orders执行Post请求 . 它希望得到: 字符串字段("email") ArrayList字段("products") 如果产品列表的大小为1 @Test public void CPlaceOrderTrue() throws Exception { String json = "{\"... -
245 votesanswersviews
Mockito:试图窥探方法是调用原始方法
我正在使用Mockito 1.9.0 . 我想在JUnit测试中模拟一个类的单个方法的行为,所以我有 final MyClass myClassSpy = Mockito.spy(myInstance); Mockito.when(myClassSpy.method1()).thenReturn(myResults); 问题是,在第二行, myClassSpy.method1() 实际上被调用,... -
253 votesanswersviews
将Mockito模拟注入Spring bean
我想将一个Mockito模拟对象注入Spring(3)bean中,以便使用JUnit进行单元测试 . 我的bean依赖项目前通过在私有成员字段上使用 @Autowired 注释来注入 . 我考虑过使用 ReflectionTestUtils.setField ,但我希望注入的bean实例实际上是一个代理,因此不会声明目标类的私有成员字段 . 我不希望创建一个依赖的公共setter,因为我将修改我的... -
0 votesanswersviews
如何使用JUnit在Spring Boot中公共方法中模拟私有方法
我想问你几个问题,并征求你的意见: 我想测试我的公共方法(我使用Spring Boot,Mockito,JUnit): @Service public class MyClass{ public Long getClientId(List<String> nameSurname) throws AuthorizationException { Long operato... -
4 votesanswersviews
单元测试中的Spring Boot数据源
我有一个简单的Spring Boot Web应用程序,它从数据库中读取并返回JSON响应 . 我有以下测试配置: @RunWith(SpringRunner.class) @SpringBootTest(classes=MyApplication.class, properties={"spring.config.name=myapp"}) @AutoConfigureMock... -
0 votesanswersviews
不能在junit测试中模拟对象
我有一个代码需要进行单元测试 @ManagedBean @SessionScoped public class XC implements Serializable { public void applyX(){ FacesContext context = FacesContext.getCurrentInstance(); if (!context.... -
6 votesanswersviews
在Kotlin中用<reified T:Any> <reified T>有什么不同?
通过下面的测试课程 . class SimpleClassTest { private inline fun <reified T> anyObject(): T { return Mockito.anyObject<T>() } lateinit var simpleObject: SimpleClass @Mock l... -
1 votesanswersviews
由于方法在使用泛型方法的抽象类中,Mockito在NoSuchMethodError上失败
我正在进行一些服务测试,我正在测试一个从使用泛型的类扩展的具体类 . 服务层的示例设置如下: public abstract class AbstractService <E extends AbstractEntity, IT extends AbstractItem> { public void deleteAllItems(E entity) { Lis... -
0 votesanswersviews
在调用.thenReturn失败之前使用any()来存根
我在StackOverflow中的第一个问题 . 试图寻找答案,但我找不到与我的问题有关的任何问题 . import org.junit.runner.RunWith import org.scalatest.junit.JUnitRunner import org.scalatra.test.scalatest.ScalatraFunSuite import org.mockito.Mockit... -
9 votesanswersviews
如何测试在Kotlin中调用顶级函数的代码?
我对Kotlin很新 . 我有一个类调用顶级函数(进行http调用) . 我正在尝试为我的 class 编写单元测试而不用它去网络 . 有没有办法模拟/ powermock /拦截从我的 class 到Kotlin顶级功能的呼叫? class MyClass { fun someMethod() { // do some stuff "http:/... -
0 votesanswersviews
使用Java Mockito模拟Kotlin方法
所以我将一个小的Java代码库迁移到Kotlin只是为了好玩,我已经迁移了这个Java类: public class Inputs { private String engineURL; private Map<String, String> parameters; public Inputs(String engineURL, Map<String, ... -
0 votesanswersviews
使用mockito使用三个参数对方法进行存根
我想使用Mockito创建一个带有三个参数的方法的存根,但我得到空指针异常 say A(String str, Object[] args, Integer.class) 为此我正在做 Mockito.when( jdbcTemplate.queryForObject( Mockito.anyString(), Mockito.eq(args), ... -
1 votesanswersviews
使用Mockito模拟一个post请求会在“when(event.request() . getParam(”type“))上抛出NullPointerException . thenReturn(”application / octet-stream“);”
我正在尝试使用Mockito模拟文件上传(使用Vertx),但它会在 when(event.request().getParam("type")).thenReturn("application/octet-stream"); 上使用的 NullPointerError 上抛出 NullPointerError 我的单元测试如下: private Uploa... -
0 votesanswersviews
java.lang.AssertionError:预期状态:<200>但是:<404>带有jersy-spring
控制器文件[LogController.java文件]: @Api(value = "/") @Path("/") public class LogController { private Logger logger = LoggerFactory.getLogger(LogController.class); private Logge... -
0 votesanswersviews
如何模拟REST请求
我在JUnit中使用Mockito,我有一个使用RestTemplate向微服务请求的方法 . private static final String REQUESTOR_API_HOST = "http://localhost:8090/requestor/v1/requestors/"; public TokenRequestorPayload getTokenReque... -
2 votesanswersviews
Spring JUnit和Mockito - SimpleJdbcTemplate
给定一个扩展SimpleJdbcDaoSupport的类,你如何模拟SimpleJdbcTemplate? public class SimpleJdbcDaoSupportExtension extends SimpleJdbcDaoSupport { public SimpleJdbcDaoSupportExtension (JdbcTemplate jdbcTemplate){... -
5 votesanswersviews
验证在RxJava订阅服务器的onNext中调用该方法
我有以下方法使用Retrofit服务接口从API获取一些数据,然后与 view 接口进行交互 . @Override @VisibleForTesting public void fetchPhotos(@Nullable PhotosService service, @Nullable Scheduler subscribeOn) { view.showLoading(); R... -
0 votesanswersviews
mapstruct junit test NullPointerException
我正在为映射类进行单元测试,但每次它都显示NullPointerException @Mapper(componentModel = "spring") public abstract class CountryMapper implements EntityMapper<CountryDTO, Country> { static final public C...