我正在创建一项集成测试:
@RunWith(CdiRunner.class)
@AdditionalClasses({FollowUpActivityRepository.class, SettingsPropertiesProducer.class})
public class FollowUpActivityFeaturesTest {
@Inject protected FollowUpActivityService fuaService;
@Test
public void DigitalInputTOFollowUpActivityFIELDS()
{
FollowUpActivityDTO dto = new FollowUpActivityDTO();
dto.setId("id");
dto.setTimestamp(Date.from(Instant.now()));
dto.setDueTimestamp(Date.from(Instant.now()));
dto.setClosingTimestamp(Date.from(Instant.now()));
dto.setMatter("matter");
dto.setComment("comment");
this.fuaService.createOrUpdate(dto);
}
}
createOrUpdate
的作用类似于:
public void createOrUpdate(FollowUpActivityDTO dto) throws RepositorySystemException
所以,我需要检查此异常是否未被抛出。
我想要优雅地完成它。
实际上,我正在使用junit 4.12和hamcrest 2.0.0.0。
有什么想法吗?
示例
在.NET中,我正在使用NSubstitute来实现:
this.apiClient.Invoking(c => c.GrantAuthorization()).ShouldNotThrow();
NullPointerException
,你想让这个测试通过吗? - Breandán Daltonthis.fuaService.createOrUpdate(dto)
可能会抛出RepositoryException
异常,而 Java 编译器告诉我需要在测试方法签名中添加try/catch
或者添加一个throws declaration
。对不起!我在帖子中添加了一个使用 NSubstitute 的示例。 - Jordi