- Mockito Cookbook
- Marcin Grzejszczak
- 216字
- 2021-07-16 11:35:00
Adding additional Mockito warnings to your tests (JUnit) (Experimental)
If you would like Mockito to append some additional warning messages to the console, which would help you when your test fails, then this recipe is perfect for you. It's very much related to the previous one so, in order to understand the background, please refer to the introductory part of the previous recipe.
How to do it...
If you want to have more information presented in your error message, you have to perform the following steps:
- Annotate your JUnit test with
@RunWith(ConsoleSpammingMockitoJUnitRunner.class)
. - Define your mocks and perform stubbing inside the test method (unfortunately, you can't use annotations or initialize fields outside test methods).
What happens then is that additional exception messages gets printed on the console after the exception that is thrown:
This stubbing was never used -> at ....MeanTaxFactorCalculatorTest.should_calculate_mean_tax_factor(MeanTaxFactorCalculatorTest.java:25)
How it works...
When the test is run, ConsoleSpammingMockitoJUnitRunner
appends a listener that finds all the stubs through WarningsCollector
, including the unused stubs for given mocks. When all of the warnings get collected, the ConsoleMockitoLogger
class prints them to the console after the test has failed.
- PyTorch深度學(xué)習(xí)實(shí)戰(zhàn):從新手小白到數(shù)據(jù)科學(xué)家
- Unity 5.x Game AI Programming Cookbook
- Spark大數(shù)據(jù)分析實(shí)戰(zhàn)
- 醫(yī)療大數(shù)據(jù)挖掘與可視化
- 數(shù)亦有道:Python數(shù)據(jù)科學(xué)指南
- 數(shù)據(jù)庫(kù)原理與應(yīng)用(Oracle版)
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- 云原生數(shù)據(jù)中臺(tái):架構(gòu)、方法論與實(shí)踐
- 大數(shù)據(jù)與機(jī)器學(xué)習(xí):實(shí)踐方法與行業(yè)案例
- 云計(jì)算寶典:技術(shù)與實(shí)踐
- 中國(guó)云存儲(chǔ)發(fā)展報(bào)告
- Access 2016數(shù)據(jù)庫(kù)應(yīng)用基礎(chǔ)
- 智能與數(shù)據(jù)重構(gòu)世界
- Arquillian Testing Guide
- Access 2010數(shù)據(jù)庫(kù)應(yīng)用技術(shù)教程(第二版)