From 369c2bd192c7c75469292cc4d565a6f3c3887809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E6=88=9F?= Date: Tue, 19 Jan 2021 15:34:02 +0800 Subject: [PATCH] put parameter constructor doc to sidebar --- README.md | 7 +++---- docs/en-us/doc/parameter-constructor.md | 6 +++--- docs/en-us/doc/setup.md | 21 +++++++++++++++++++-- docs/en-us/sidebar.md | 3 ++- docs/zh-cn/doc/parameter-constructor.md | 4 ++-- docs/zh-cn/doc/setup.md | 21 +++++++++++++++++++-- docs/zh-cn/doc/use-maven-plugin.md | 8 +++++--- docs/zh-cn/sidebar.md | 3 ++- 8 files changed, 55 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 89556f0..5e9f0fe 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,8 @@ 阅读[这里](https://mp.weixin.qq.com/s/KyU6Eu7mDkZU8FspfSqfMw)了解更多故事。 > 特别说明 -> 1. 如有遇到启动报空指针异常或"Operand stack overflow"错误,请升级`TestableMock`版本,这是BUG,已修复😛 -> 2. 如遇到"Attempt to access none-static member in mock method"错误,参见[常见问题](https://alibaba.github.io/testable-mock/#/zh-cn/doc/frequently-asked-questions)第8条 -> 3. 如果有遇到其他任何使用问题和建议,请直接在[Issue](https://github.com/alibaba/testable-mock/issues)中提出,也可通过[Pull Request](https://github.com/alibaba/testable-mock/pulls)提交您的代码,我们将在24小时内回复并处理 +> 1. 如遇到"Attempt to access none-static member in mock method"错误,参见[常见问题](https://alibaba.github.io/testable-mock/#/zh-cn/doc/frequently-asked-questions)第8条 +> 2. 如果有遇到其他任何使用问题和建议,请直接在[Issue](https://github.com/alibaba/testable-mock/issues)中提出,也可通过[Pull Request](https://github.com/alibaba/testable-mock/pulls)提交您的代码,我们将在24小时内回复并处理 ----- @@ -22,7 +21,7 @@ - `0.4.x` 当前版本,进行中的工作内容参考[Issue](https://github.com/alibaba/testable-mock/issues)清单 - `0.5` 实现以"Mock方法集"为单元的Mock方法复用机制,让测试类之间可以方便复用相同的Mock方法 -- `0.6` 实现第四项单元测试增强能力"快速入参构造器"。不论被测方法所需的参数结构多么错综复杂、甚至没有合适的构造方法、甚至需要私有内部类对象... 呼唤TestableMock,马上递给您~ +- `0.5.?` 实现第四项单元测试增强能力"[快速入参构造器]()" ## 目录结构 diff --git a/docs/en-us/doc/parameter-constructor.md b/docs/en-us/doc/parameter-constructor.md index 730a7c7..108a21a 100644 --- a/docs/en-us/doc/parameter-constructor.md +++ b/docs/en-us/doc/parameter-constructor.md @@ -1,6 +1,6 @@ -Quickly construct complex input parameters +Parameter constructor --- -Generate arbitrarily nested object instances, simplify their internal member assignment methods, and solve the problem of lengthy initialization code for the parameters of the tested method. +No matter how intricate the parameter structure required by the method under test is, even there is no suitable construction method, or even there are private internal class objects... Call `TestableMock`, the parameter object will be handed to you immediately~ -This feature is planned to be released in the `0.6` version. +This feature is planned to be released in the `0.5.x` version. diff --git a/docs/en-us/doc/setup.md b/docs/en-us/doc/setup.md index e4bfcc6..3a6fede 100644 --- a/docs/en-us/doc/setup.md +++ b/docs/en-us/doc/setup.md @@ -3,9 +3,10 @@ Use TestableMock `TestableMock` is an assist tool for Java unit testing based on source code and bytecode enhancement, including the following functions: +- [Quickly mock arbitrary call](en-us/doc/use-mock.md): quickly replace any method invocation in the class under test with a mock method, solve the cumbersome use of traditional mock tools problem - [Access private members of the class under test](en-us/doc/private-accessor.md): enable unit tests directly invoke or access private members of the class under test, solve the problems of private member initialization and private method testing -- [Quick mock arbitrary call](en-us/doc/use-mock.md): quickly replace any method invocation in the class under test with a mock method, solve the cumbersome use of traditional mock tools problem - [Auxiliary test void method](en-us/doc/test-void-method.md): use the mock validator to check the internal logic of method, solve the problem that unit testing is difficult to implement to the method with no return value +- [Quickly construct complicated parameter object](en-us/doc/parameter-constructor.md):generate arbitrarily nested object instances, simplify their internal member assignment methods, solve the problem of long initialization codes for method parameters ## Use in Maven project @@ -67,7 +68,7 @@ dependencies { } ``` -Then add javaagent to `test` configuration: +Then add `javaagent` to "test" configuration: ```groovy test { @@ -76,3 +77,19 @@ test { ``` See the [build.gradle](https://github.com/alibaba/testable-mock/blob/master/demo/java-demo/build.gradle) file of project `java-demo` and the [build.gradle.kts](https://github.com/alibaba/testable-mock/blob/master/demo/kotlin-demo/build.gradle.kts) file of project `kotlin-demo`. + +> For Android project tested with `Robolectric` framework, please use the same method to add `TestableMock` dependency as above, and add `javaagent` configuration as follows: +> +> ```groovy +> android { +> testOptions { +> unitTests { +> all { +> jvmArgs "-javaagent:${classpath.find { it.name.contains("testable-agent") }.absolutePath}" +> } +> } +> } +> } +> ``` +> +> See [issue-43](https://github.com/alibaba/testable-mock/issues/43) for a complete example. diff --git a/docs/en-us/sidebar.md b/docs/en-us/sidebar.md index ec80a2f..e873a2a 100644 --- a/docs/en-us/sidebar.md +++ b/docs/en-us/sidebar.md @@ -1,8 +1,9 @@ - Quick Start - [Use TestableMock](en-us/doc/setup.md) - - [Private Accessor](en-us/doc/private-accessor.md) - [Fast Mocking](en-us/doc/use-mock.md) + - [Private Accessor](en-us/doc/private-accessor.md) - [Test Void Method](en-us/doc/test-void-method.md) + - [Parameter constructor](en-us/doc/parameter-constructor.md) - Usage Guide - [Verify Mock Invocation](en-us/doc/invoke-matcher.md) diff --git a/docs/zh-cn/doc/parameter-constructor.md b/docs/zh-cn/doc/parameter-constructor.md index a0ee925..21dc539 100644 --- a/docs/zh-cn/doc/parameter-constructor.md +++ b/docs/zh-cn/doc/parameter-constructor.md @@ -1,6 +1,6 @@ 快速构造复杂入参 --- -生成任意多层嵌套的对象实例,并简化其内部成员赋值方式,解决被测方法参数初始化代码冗长的问题。 +不论被测方法所需的参数结构多么错综复杂、甚至没有合适的构造方法、甚至需要私有内部类对象... 呼唤TestableMock,马上递给您~ -计划在`0.6`版本中推出。 +计划在`0.5.x`版本中推出。 diff --git a/docs/zh-cn/doc/setup.md b/docs/zh-cn/doc/setup.md index 1c8e7f8..75e051c 100644 --- a/docs/zh-cn/doc/setup.md +++ b/docs/zh-cn/doc/setup.md @@ -3,9 +3,10 @@ `TestableMock`是基于源码和字节码增强的Java单元测试辅助工具,包含以下功能: -- [访问被测类私有成员](zh-cn/doc/private-accessor.md):使单元测试能直接调用和访问被测类的私有成员,解决私有成员初始化和私有方法测试的问题 - [快速Mock任意调用](zh-cn/doc/use-mock.md):使被测类的任意方法调用快速替换为Mock方法,实现"指哪换哪",解决传统Mock工具使用繁琐的问题 +- [访问被测类私有成员](zh-cn/doc/private-accessor.md):使单元测试能直接调用和访问被测类的私有成员,解决私有成员初始化和私有方法测试的问题 - [辅助测试void方法](zh-cn/doc/test-void-method.md):利用Mock校验器对方法的内部逻辑进行检查,解决无返回值方法难以实施单元测试的问题 +- [快速构造参数对象](zh-cn/doc/parameter-constructor.md):生成任意多层嵌套的对象实例,并简化其内部成员赋值方式,解决被测方法参数初始化代码冗长的问题 ## 在Maven项目中使用 @@ -58,7 +59,7 @@ ## 在Gradle项目中使用 -在`build.gradle`文件中添加TestableMock依赖: +在`build.gradle`文件中添加`TestableMock`依赖: ```groovy dependencies { @@ -76,3 +77,19 @@ test { ``` 参见项目`java-demo`的[build.gradle](https://github.com/alibaba/testable-mock/blob/master/demo/java-demo/build.gradle)和`kotlin-demo`的[build.gradle.kts](https://github.com/alibaba/testable-mock/blob/master/demo/kotlin-demo/build.gradle.kts)文件。 + +> 若是基于`Robolectric`框架的Android项目,则添加`TestableMock`依赖方法同上,添加javaagent配置方法如下: +> +> ```groovy +> android { +> testOptions { +> unitTests { +> all { +> jvmArgs "-javaagent:${classpath.find { it.name.contains("testable-agent") }.absolutePath}" +> } +> } +> } +> } +> ``` +> +> 完整示例参考[issue-43](https://github.com/alibaba/testable-mock/issues/43) diff --git a/docs/zh-cn/doc/use-maven-plugin.md b/docs/zh-cn/doc/use-maven-plugin.md index 4debf0b..c78aa53 100644 --- a/docs/zh-cn/doc/use-maven-plugin.md +++ b/docs/zh-cn/doc/use-maven-plugin.md @@ -19,13 +19,15 @@ ``` -> 当使用`testable-maven-plugin`插件时,应该移除`maven-surefire-plugin`插件上的TestableMock相关配置 +**注意:**当使用`testable-maven-plugin`插件时,应该移除`maven-surefire-plugin`插件上的TestableMock相关配置。 `testable-maven-plugin`插件能够与Jacoco插件直接同时使用,无需额外适配,因此能使`pom.xml`文件编写起来更简单且美观。 -但需要注意的是,当通过IDE运行单个测试用例时,Mock功能会失效。 +> 还有一种特殊情况,当`jacoco`插件是通过`maven`命令行参数引入的时候,若要使用`TestableMock`功能,则也必须通过命令行参数引入`testable-maven-plugin`插件。详见[issue-14](https://github.com/alibaba/testable-mock/issues/14)。 -这是由于IDE运行单个测试用例时通常都只会运行`maven-surefire-plugin`插件,跳过了`testable-maven-plugin`插件执行,导致Mock功能所需的JavaAgent没有随测试注入。 +但需要注意的是,使用`testable-maven-plugin`插件后,通过IntelliJ IDE运行单个测试用例时,Mock功能会失效。 + +这是由于IntelliJ IDE运行单个测试用例时只会运行`maven-surefire-plugin`插件,跳过了`testable-maven-plugin`插件执行,导致Mock功能所需的JavaAgent未随测试注入。 该问题可以通过额外配置IDE的测试参数绕过。以IntelliJ为例,打开运行菜单的"编辑配置..."选型,如图中位置① diff --git a/docs/zh-cn/sidebar.md b/docs/zh-cn/sidebar.md index 7571e0b..4117f4d 100644 --- a/docs/zh-cn/sidebar.md +++ b/docs/zh-cn/sidebar.md @@ -1,8 +1,9 @@ - 快速上手 - [使用TestableMock](zh-cn/doc/setup.md) - - [直接访问私有成员](zh-cn/doc/private-accessor.md) - [快速Mock任意方法](zh-cn/doc/use-mock.md) + - [直接访问私有成员](zh-cn/doc/private-accessor.md) - [测试无返回值的方法](zh-cn/doc/test-void-method.md) + - [快速构造复杂入参](zh-cn/doc/parameter-constructor.md) - 使用指南 - [校验Mock调用](zh-cn/doc/invoke-matcher.md)