Introduce the MOCK class with anonymous classes

xiaoxiao2021-03-06  72

Public class a {

Public void action () {

....

// Findsomethingthroghclassb logic;

....

}

}

First extract some of the part of the part of B into a protected method into a protected method.

Public class a {

Public void action () {

....

FINDSMETHINGTHROGHCLASSB ();

....

}

Protected void findsomethingthroghclassb () {

// Findsomethingthroghclassb logic;

}

}

Then create a in TestCase

A a = new a () {

Protected void findsomethingthroghclassb () {

Mockit ();

}

}

This can use MOCK directly in the test.

Compared to other methods, this method is smaller for Class A, and does not require new type variables.

转载请注明原文地址:https://www.9cbs.com/read-92549.html

New Post(0)