![]() Now we will try to an example for mock final class called StringUtility that contain function called allCharacterToUpperCase //Classįun allCharacterToUpperCase(str: String) = str.map. most of classes depend on another classes the main purpose of mockito that mock these dependency classes The main purpose of unit testing is to test components in isolation from each other and that is how our code should be written as well. * or we can go to our classes that we wanna to mock and make it open it is not best way bcs i will change my code just to mock classes Why we need to use mockito ? The line above indicated Mockito Framework that we can now mock any final classes. **Hint KOTLIN classes can't be mocked bcs all classes in KOTLIN is final by default **To solve the problem we need to create an directory under resources directory called "mockito-extensions" and inside it we need to create file called "" inside this file paste the line "mock-maker-inline" TestImplementation 'org.mockito:mockito-core:2.27.0' To work with mockito we need to add these 2 lines in gradle testImplementation 'junit:junit:4.12' ![]() Mockito tests are very readable and they produce clean verification errors. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |