- 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.
- 大規(guī)模數(shù)據(jù)分析和建模:基于Spark與R
- 大數(shù)據(jù)技術(shù)基礎
- Mastering Ninject for Dependency Injection
- Voice Application Development for Android
- 正則表達式必知必會
- 數(shù)亦有道:Python數(shù)據(jù)科學指南
- 智慧的云計算
- 數(shù)字IC設計入門(微課視頻版)
- R Object-oriented Programming
- Filecoin原理與實現(xiàn)
- 企業(yè)大數(shù)據(jù)處理:Spark、Druid、Flume與Kafka應用實踐
- Access 2016數(shù)據(jù)庫應用基礎
- 離線和實時大數(shù)據(jù)開發(fā)實戰(zhàn)
- 大數(shù)據(jù)技術(shù)體系詳解:原理、架構(gòu)與實踐
- 領(lǐng)域驅(qū)動設計精粹