依賴的pom
<dependency>
<groupId>org.evosuite</groupId>
<artifactId>evosuite-standalone-runtime</artifactId>
<version>1.0.6</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.7.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.7.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
代碼
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* @Description:
* @Author:
* @CreateDate: 2019/12/13 16:24
* @Version: 1.0
*/
@PowerMockIgnore("*")
@RunWith(PowerMockRunner.class)
public class UserRegisterActivityEventProcessorTest {
@InjectMocks
private UserRegisterActivityEventProcessor userRegisterActivityEventProcessor;
@Mock
private ProductCustomerRelService productCustomerRelService;
@Test
public void userRegister(){
PowerMockito.when(productCustomerRelService.addRecord(null)).thenReturn(1);
EventDTO eventDTO =new EventDTO();
eventDTO.setEventType(EventEnum.USER_REGISTER.name());
eventDTO.setData("{\"memberId\":\"1\",\"referrerMemberId\":\"2\"}");
userRegisterActivityEventProcessor.handle(eventDTO);
}
}
UserRegisterActivityEventProcessor 是你需要測(cè)試的業(yè)務(wù)
ProductCustomerRelService 是需要mock的service