testng
In the Mockito Tutorial, we used JUnit to run test cases. Mockito framework can be combined with other Java testing frameworks too. In this tutorial, we will integrate Mockito mocking framework with TestNG testing framework.
在Mockito教程中 ,我们使用JUnit运行测试用例。 Mockito框架也可以与其他Java测试框架结合。 在本教程中,我们将把Mockito模拟框架与TestNG测试框架集成在一起。
TestNG Mockito (TestNG Mockito)
We will reuse the classes created in the Mockito Tutorial and write test cases for them in TestNG. You can download the complete code from our GitHub Repository to check out these classes. To give a brief idea, we have following classes.
我们将重用Mockito教程中创建的类,并在TestNG中为其编写测试用例。 您可以从我们的GitHub存储库下载完整的代码,以检查这些类。 为简单起见,我们有以下课程。
AddService
interface andAddServiceImpl
implementation class.AddService
接口和AddServiceImpl
实现类。CalcService
is the service class that has dependency onAddService
.CalcService
是依赖于AddService
的服务类。
Our goal is to test CalcService
class methods, so we will mock AddService
using Mockito rather than creating its instance.
我们的目标是测试CalcService<