com.github.mht-xyt:automock

全自动生成mock srvice代码的类,并放入test目录下,并自动执行。 只需要引用此包,并调用AutoMock中的mock或mockPkg 即可; *生成的代码在/src/test/java/mock/下 *项目需遵从/src/main/java结构

License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

com.github.mht-xyt
ArtifactId

ArtifactId

automock
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

全自动生成mock srvice代码的类,并放入test目录下,并自动执行。 只需要引用此包,并调用AutoMock中的mock或mockPkg 即可; *生成的代码在/src/test/java/mock/下 *项目需遵从/src/main/java结构
Source Code Management

Source Code Management

https://github.com/mht-xyt/automock

Download automock

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mht-xyt/automock/ -->
<dependency>
    <groupId>com.github.mht-xyt</groupId>
    <artifactId>automock</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mht-xyt/automock/
implementation 'com.github.mht-xyt:automock:1.0'
// https://jarcasting.com/artifacts/com.github.mht-xyt/automock/
implementation ("com.github.mht-xyt:automock:1.0")
'com.github.mht-xyt:automock:jar:1.0'
<dependency org="com.github.mht-xyt" name="automock" rev="1.0">
  <artifact name="automock" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mht-xyt', module='automock', version='1.0')
)
libraryDependencies += "com.github.mht-xyt" % "automock" % "1.0"
[com.github.mht-xyt/automock "1.0"]

Dependencies

compile (7)

Group / Artifact Type Version
org.apache.commons : commons-lang3 jar 3.7
org.apache.commons : commons-collections4 jar 4.4
com.github.houbb : data-factory-core jar 0.0.3
org.mockito : mockito-core jar 1.10.19
org.projectlombok : lombok jar 1.18.4
com.alibaba : fastjson jar 1.2.62
junit : junit jar 4.13

Project Modules

There are no modules declared in this project.

automock

轻量级全自动mock

只需要一个jar包,全自动完成java的mock操作,使用极其简单

<groupId>com.github.mht-xyt</groupId>

<artifactId>automock</artifactId>

<version>1.0</version>

maven地址 :https://mvnrepository.com/artifact/com.github.mht-xyt/automock/1.0

只需要一行代码直接调用

/**

  • mock 一个类

  • @param fullPkg 全限定的包名+类名:如 com.mht.auto.mock.AutoMock

*/

AutoMock.mock(pkg);

/**

  • mock 包下所有类

  • @param fullPkg 全限定的包名:如 com.mht.auto.mock

*/

AutoMock.mockPkg(pkg);

============================================================================

以下都是效果和说明

执行输出效果:



/ \ / \ / \ / \ / \ / \ / \ / \

( A ( u ( t ( o ( m ( o ( c ( k )

_/ _/ _/ _/ _/ _/ _/ _/

欢迎使用AutoMock自动化工具,本工具可生成mock测试类并加载执行:

mock测试类生成位于src/test/java/mock目录下,如有自定义改动请自取。

本次执行:


-----[SchedulerJobServiceImpl].[releaseJobs] start......

| |

| |

-----[SchedulerJobServiceImpl].[releaseJobs] mock success!

-----[SchedulerJobServiceImpl].[runJob] start......

| |

| |

-----[SchedulerJobServiceImpl].[runJob] mock success!


项目结构必须是:

src

main

java

test

java

运行过程:

1 自动读取java文件

2 自动根据原文件生成mock测试类文件

3 自动格式化写出测试类文件

4 自动热加载文件,并执行mock的方法

生成的mock文件样例:


package mock;

import static org.mockito.Mockito.any;

import static org.mockito.Mockito.anyInt;

import static org.mockito.Mockito.when;

import com.core.util.DataUtil;

import com.test.server.test.easy.vo.Result;

import org.junit.Before;

import org.junit.Test;

import org.mockito.InjectMocks;

import org.mockito.Mock;

import org.mockito.MockitoAnnotations;

public class TestJobServiceImplTest {

@InjectMocks TestJobServiceImpl testJobServiceImpl = new TestJobServiceImpl();

@Mock TestService testService;

@Before

public void setUp() {

MockitoAnnotations.initMocks(this);

}

@Test

public void releaseJobs() {

String projectName = DataUtil.build(String.class);

String jobName = DataUtil.build(String.class);

int online = 1;

Result result = DataUtil.build(Result.class);

when(this.processDefinitionService.queryProcessDefinitionListPaging(

        any(), any(), anyInt(), anyInt(), any()))

    .thenReturn(result);

Result scheduleResult = DataUtil.build(Result.class);

when(this.testService.queryTest(any(), anyInt(), any(), anyInt(), anyInt()))

    .thenReturn(scheduleResult);

when(this.testService.setTestStateOffline(any(), anyInt())).thenReturn(null);

when(this.testService.setTestState(any(), anyInt())).thenReturn(null);

this.testJobServiceImpl.releaseJobs(projectName, jobName, online);

}

}


可直接运行,有自定义mock操作可直接修改即可。使用无比方便,一键批量生成。

Versions

Version
1.0