腾讯云
开发者社区
文档
建议反馈
控制台
首页
学习
活动
专区
工具
TVP
最新优惠活动
文章/答案/技术大牛
搜索
搜索
关闭
发布
登录/注册
精选内容/技术社群/优惠产品,
尽在小程序
立即前往
文章
问答
(1918)
视频
沙龙
2
回答
模拟
存储
库函数
会
导致
空
指针
异常
,
尽管
使
用了
when
和
thenReturn
java
、
spring
、
spring-boot
、
unit-testing
、
junit
尽管
在测试中使
用了
when
(guildUsersRepository.save(guildUsers)).
thenReturn
(guildUsers);,我还是遇到了一个
空
指针
异常
,跟踪如下: java.lang.NullPointerException在
模拟
Test类中的类时,需要做哪些不同的操作?
when
(guildRepository.findById(any())).
thenReturn
(Optional.o
浏览 42
提问于2020-10-25
得票数 0
回答已采纳
1
回答
指定为非null的参数为null:方法com.craftboxx.toolbar.HeaderData.<init>,参数syncStatus
android
、
unit-testing
、
kotlin
、
mockito
、
android-viewmodel
当我为我的AssignmentViewmodelTest.kt运行单元测试时,我会得到以下
异常
: val user = headerData.getUserlet { status ->
wh
浏览 6
提问于2022-04-14
得票数 0
2
回答
检测到Mockito Null
指针
异常
和
未完成的存根
java
、
unit-testing
、
junit
、
mocking
、
mockito
[] object = (Object[]) query.getSingleResult();
when
(entityManagerMock.createNativeQuery(Mockito.anyString()).getSingleResult()).
thenReturn
(fixture);
when
(mock.isOk()).
then
浏览 1
提问于2020-04-18
得票数 1
2
回答
在SimpleDateFormat测试中
模拟
数据格式( JUnit )
java
、
unit-testing
、
junit
、
mockito
、
simpledateformat
(mockSqlConnection.getConnection()).
thenReturn
(mockConn);
when
(mockPreparedStmnt.executeQuery()).
thenReturn
(mockResultSet);
when
(mockResultSet.nex
浏览 5
提问于2018-06-05
得票数 1
回答已采纳
1
回答
如何在scala中
模拟
参数为新实例的方法
scala
、
unit-testing
、
mockito
、
scalatest
、
scalamock
: Future[Int]acr.delete(Token(token), client, scope)当我试图在测试中
模拟
delete方法时,我会这样做: .delete( scope = any[Scope]
浏览 11
提问于2020-12-09
得票数 0
回答已采纳
1
回答
在Spring中使用jUnit
模拟
对象
spring
、
unit-testing
、
spring-mvc
、
intellij-idea
、
junit
代码本身似乎很好,但是由于某些原因,我一直在我的
When
语句上得到一个
空
指针
异常
。(testPerson.getFirstName()).
thenReturn
(firstName); // Throws NullPointerException
when
(testPerson.getLastName出于争论的考虑(而且由于我需要使用@Mock的其他项目往往会发出同样的抱怨),我需要知道如何使用@Mock注释
和
SpringJUnit4C
浏览 3
提问于2015-05-26
得票数 0
回答已采纳
2
回答
使用Mockito进行单元测试时的
空
指针
java
、
spring-boot
、
junit
、
mockito
我正在尝试使用mockito对我的服务实现进行单元测试,以
模拟
出细节。该服务将向数据库中添加一个新的建筑实体。下面是服务实现
和
测试实现。telephone("4444444444") .address("testAddress").build();
when
(buildingServiceImpl.addBuilding(any(BuildingRequest.class))).
th
浏览 0
提问于2020-01-02
得票数 0
1
回答
在使用模仿:想要但不被调用的测试中出错:
spring
、
unit-testing
、
junit
、
mocking
findAll(pageableCaptor.capture());,所以我的自定义断言不能影响这个错误的发生,这个错误看起来是:想要但没有被调用: bookRepository.findAll();实际上,这个
模拟
没有交互
浏览 2
提问于2022-06-20
得票数 0
回答已采纳
5
回答
当().
thenReturn
不必要地调用方法时,Mockito
java
、
testing
、
junit
、
mockito
checkXRequirement_NullProduct_AddAction_ShouldThrowNullPointerException() throws CustomException { Product product = null;
when
(BasketHelper.getActionProduct(site, request)).
then
浏览 6
提问于2013-08-20
得票数 17
回答已采纳
5
回答
doReturn()
和
when
()之间的差异
java
、
unit-testing
、
mockito
我目前正在使用Mockito在Spring应用程序中
模拟
我的服务层对象,我想在这个应用程序中测试我的Controller方法。但是,正如我一直在阅读关于Mockito的具体内容一样,我发现doReturn(...).
when
(...)方法与
when
(...).
thenReturn
(...)相当。所以,我的问题是,有两个做同样事情的方法有什么意义,或者doReturn(...).
when
(...)
和
when
(...).
thenReturn
(...)之间有
浏览 2
提问于2013-12-03
得票数 284
回答已采纳
2
回答
Spring & Mockito :在单元测试中调用的实际对象
java
、
spring
、
unit-testing
、
junit
、
mockito
AuthErrorResponseWriter ();
when
(responseMock.getWriter()).
thenReturn
(writerMock); /verify(responseMock).setStatus(HttpStatus.FORBIDDEN.value
浏览 4
提问于2017-01-13
得票数 0
回答已采纳
2
回答
单元测试不像预期的那样工作-而不是404,它返回200作为状态代码。
java
、
spring-boot
、
unit-testing
、
spring-mvc
、
mockito
我在一个数据库中有一些账户: iban,货币
和
余额。 accountEntity.setCurrency("RON"); } @Tes
浏览 0
提问于2020-05-11
得票数 1
回答已采纳
2
回答
如何正确地
模拟
UriInfo?
java
、
url
、
junit
、
mockito
UriInfo mockUriInfo;
when
(mockUriInfo.getRequestUri
浏览 1
提问于2015-04-21
得票数 0
回答已采纳
3
回答
形成Mockito“语法”
java
、
unit-testing
、
junit
、
mocking
、
mockito
: Stubberthen(T) : OngoingStubbing当您在实践中看到Mockito的示例时,您会看到如下代码:从我所读过的所有文档中,我已经识别出了Mockito我发现的一些常见模式如下: 提供/遗嘱: given(yourMethod()
浏览 7
提问于2012-07-13
得票数 53
回答已采纳
2
回答
用莫基托嘲弄吐瓦里奥
java
、
oop
、
unit-testing
、
mockito
、
twilio
testShouldReturnTrueIfAccountNameFound() {
when
(account.getFriendlyName()).
thenReturn
("test");
when</
浏览 3
提问于2013-06-11
得票数 0
1
回答
莫奇托的InvocationTargetException
java
、
junit
、
mockito
我在测试用例中得到了InvocationTarget
异常
。(facade1.queryInfo(Mockito.anyString()).getInfo()).
thenReturn
(getInfo()); Mockito.
when
(facade3.isWhitelisted()).
thenReturn
(true嗯可以是
空<
浏览 2
提问于2020-03-31
得票数 0
回答已采纳
1
回答
模拟
CrudRepository findById ("111").get ()
java
、
spring
、
spring-boot
、
spring-data
、
spring-data-jpa
我需要从我的测试类中
模拟
Spring crudRepository findById("111").get()(2)有一个方法,我需要让用户给出一个id,其中服务类方法只是调用
存储
库findById("111"//here some code working well.<e
浏览 0
提问于2018-03-21
得票数 5
1
回答
Mockito : findById()不能返回布尔值
java
、
spring
、
unit-testing
、
mockito
、
boolean
this.petRepository.findById(id).isPresent()) Mockito.
when
(this.adoptionRepository.findAllByPet(pet)).
thenReturn
(由于上述语法的性质,可能会出现问题,因为: 此
异常
可能发生在错误编写的多线程
浏览 17
提问于2022-01-31
得票数 0
回答已采纳
1
回答
在串联运行测试时,似乎忽略了MockBean的作用域代理Bean
spring-boot
、
unit-testing
、
spring-mvc
、
mockito
、
junit5
(scopedBean.getAValue()).
thenReturn
("myvalue");
when
(scopedBean.matches("anotherProperty当将它们全部运行在
浏览 9
提问于2022-03-30
得票数 0
回答已采纳
1
回答
用spring boot 2.x
模拟
RestTemplate抛出
空
指针
异常
unit-testing
、
mockito
、
spring-boot-test
我正在为我的服务层编写一个单元测试,它调用REST后端服务
和
MongoDB。但是,当在本地执行测试时可以正常工作,但是当在编译时将我的应用程序打包到我的CICD管道中时,它会尝试运行单元测试,同时在使用RestTemplate
和
MongoTemplate bean时会得到
空
指针
异常
Cant able to inject restTemplate
when
(mongoTemplate.updateFirst(updateObject)).
thenReturn</em
浏览 140
提问于2021-10-01
得票数 0
点击加载更多
扫码
添加站长 进交流群
领取专属
10元无门槛券
手把手带您无忧上云
相关
资讯
Java单元测试技巧之PowerMock
震惊!恶意二维码引发微信闪退,如何确保扫码安全?
FastDFS并发会有bug,其实我也不太信?-一次并发问题的排查经历
C语言错误处理和异常处理方法和策略,如何实现非局部跳转
C加加开发易踩雷区
热门
标签
更多标签
活动推荐
运营活动
广告
关闭
领券