diff --git a/README.md b/README.md index 53e42a4..d02afae 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ 阅读[这里](https://mp.weixin.qq.com/s/KyU6Eu7mDkZU8FspfSqfMw)了解更多故事。 > 特别说明 -> 1. 如有遇到启动报空指针异常问题,请将`TestableMock`升级到`0.4.5`或以上版本 +> 1. 如有遇到启动报空指针异常问题,请升级`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)中提出,我们将在24小时内回复并处理 diff --git a/demo/java-demo/build.gradle b/demo/java-demo/build.gradle index 720a4fc..643bb17 100644 --- a/demo/java-demo/build.gradle +++ b/demo/java-demo/build.gradle @@ -12,8 +12,8 @@ repositories { dependencies { testImplementation('org.junit.jupiter:junit-jupiter:5.6.2') - testImplementation('com.alibaba.testable:testable-all:0.4.5') - testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.5') + testImplementation('com.alibaba.testable:testable-all:0.4.6') + testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.6') } test { diff --git a/demo/java-demo/pom.xml b/demo/java-demo/pom.xml index d82a0df..d21f8a6 100644 --- a/demo/java-demo/pom.xml +++ b/demo/java-demo/pom.xml @@ -12,7 +12,7 @@ 1.8 1.8 5.6.2 - 0.4.5 + 0.4.6 diff --git a/demo/kotlin-demo/build.gradle.kts b/demo/kotlin-demo/build.gradle.kts index 3657de1..0088f27 100644 --- a/demo/kotlin-demo/build.gradle.kts +++ b/demo/kotlin-demo/build.gradle.kts @@ -16,8 +16,8 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") testImplementation("org.junit.jupiter:junit-jupiter:5.6.2") - testImplementation("com.alibaba.testable:testable-all:0.4.5") - testAnnotationProcessor("com.alibaba.testable:testable-processor:0.4.5") + testImplementation("com.alibaba.testable:testable-all:0.4.6") + testAnnotationProcessor("com.alibaba.testable:testable-processor:0.4.6") } tasks.withType { diff --git a/demo/kotlin-demo/pom.xml b/demo/kotlin-demo/pom.xml index 53ea7f7..dd5e574 100644 --- a/demo/kotlin-demo/pom.xml +++ b/demo/kotlin-demo/pom.xml @@ -14,7 +14,7 @@ 1.8 1.8 5.6.2 - 0.4.5 + 0.4.6 diff --git a/docs/en-us/doc/release-note.md b/docs/en-us/doc/release-note.md index 554a94f..9e9cb95 100644 --- a/docs/en-us/doc/release-note.md +++ b/docs/en-us/doc/release-note.md @@ -1,5 +1,10 @@ # Release Note +## 0.4.6 +- fix an issue of `IINC` bytecode processing +- support `TestableTool.MOCK_CONTEXT` variable to inject extra parameters to mock context +- use `TestableTool.TEST_CASE` variable to distinguish test case is no longer recommended + ## 0.4.5 - fix private access compile error in intelliJ 2020.3+ environment - change javaagent initialization logic to avoid NPE in cross-layer test scenario @@ -44,7 +49,7 @@ ## v0.2.1 - support mock static method - support mock kotlin companion object method -- support mock invoke by interface / base class object +- support mock invoke by an interface / base class object ## v0.2.0 - use `TestableTool` class to expose test context and verify mock invoke diff --git a/docs/en-us/doc/setup.md b/docs/en-us/doc/setup.md index b208a59..e23b5d6 100644 --- a/docs/en-us/doc/setup.md +++ b/docs/en-us/doc/setup.md @@ -15,7 +15,7 @@ It is recommended to add a `property` field that identifies the TestableMock ver ```xml - 0.4.5 + 0.4.6 ``` @@ -62,8 +62,8 @@ Add dependence of `TestableMock` in `build.gradle` file: ```groovy dependencies { - testImplementation('com.alibaba.testable:testable-all:0.4.5') - testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.5') + testImplementation('com.alibaba.testable:testable-all:0.4.6') + testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.6') } ``` diff --git a/docs/en-us/doc/use-mock.md b/docs/en-us/doc/use-mock.md index 71635b2..4d7a3c2 100644 --- a/docs/en-us/doc/use-mock.md +++ b/docs/en-us/doc/use-mock.md @@ -107,9 +107,11 @@ For complete code examples, see the `should_able_to_mock_new_object()` test case #### 5. Identify the current test case and invoke source -In the mock method, you can use `TestableTool.TEST_CASE` and `TestableTool.SOURCE_METHOD` to identify **the name of the currently running test case** and **the name of the method under test before entering the mock method**, so as to distinguish different invocation source. +In the mock method, you can use the `TestableTool.SOURCE_METHOD` variable to identify **the method name of the class under test before entering the mock method**; in addition, the `TestableTool.MOCK_CONTEXT` variable can **inject additional context parameters into the mock method**, to distinguish and process different calling scenarios. -> The implementation mechanism of these two fields is based on call stack analysis. Although various special cases have been dealt with, there is still the possibility of misjudgment in complex scenarios involving multiple threads. If you find a relevant reproducible BUG, please submit an issue on Github. +Note that because `TestableMock` does not (and won't to) rely on any specific test framework, it cannot automatically identify the end position of a single test case, which makes the parameters set to the `TestableTool.MOCK_CONTEXT` variable may exist cross test cases in the same test class. It is recommended to always use `MOCK_CONTEXT.clear()` to clear the context immediately after use. You can also add this statement to the unified position where the test case ends of the specific unit test framework, such as the `@AfterEach` method of JUnit 5. + +> The `TestableTool.MOCK_CONTEXT` variable is currently shared within the test class. When the unit test runs in parallel, it is recommended to select the `parallel` type as `classes` For complete code examples, see the `should_able_to_get_source_method_name()` and `should_able_to_get_test_case_name()` test cases in the `java-demo` and `kotlin-demo` sample projects. diff --git a/docs/zh-cn/doc/release-note.md b/docs/zh-cn/doc/release-note.md index 7206d56..79e9e4d 100644 --- a/docs/zh-cn/doc/release-note.md +++ b/docs/zh-cn/doc/release-note.md @@ -1,5 +1,10 @@ # Release Note +## 0.4.6 +- 修复一处`IINC`字节码处理异常 +- 支持使用`TestableTool.MOCK_CONTEXT`变量为Mock方法注入额外上下文参数 +- 不再推荐使用`TestableTool.TEST_CASE`变量来区分测试用例 + ## 0.4.5 - 修复IntelliJ 2020.3+环境下的私有成员访问编译期错误 - 修复潜在的跨用例初始化空指针异常 (issue-20) diff --git a/docs/zh-cn/doc/setup.md b/docs/zh-cn/doc/setup.md index 23e0d8e..e71c2d9 100644 --- a/docs/zh-cn/doc/setup.md +++ b/docs/zh-cn/doc/setup.md @@ -15,7 +15,7 @@ ```xml - 0.4.5 + 0.4.6 ``` @@ -62,8 +62,8 @@ ```groovy dependencies { - testImplementation('com.alibaba.testable:testable-all:0.4.5') - testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.5') + testImplementation('com.alibaba.testable:testable-all:0.4.6') + testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.6') } ``` diff --git a/docs/zh-cn/doc/use-mock.md b/docs/zh-cn/doc/use-mock.md index adfc4f2..615115d 100644 --- a/docs/zh-cn/doc/use-mock.md +++ b/docs/zh-cn/doc/use-mock.md @@ -107,9 +107,11 @@ private BlackBox createBlackBox(String text) { #### 5. 识别当前测试用例和调用来源 -在Mock方法中可以通过`TestableTool.TEST_CASE`和`TestableTool.SOURCE_METHOD`来识别**当前运行的测试用例名称**和**进入该Mock方法前的被测类方法名称**,从而区分处理不同的调用场景。 +在Mock方法中可以通过`TestableTool.SOURCE_METHOD`变量来识别**进入该Mock方法前的被测类方法名称**;此外,通过`TestableTool.MOCK_CONTEXT`变量能够为Mock方法注入**额外的上下文参数**,从而区分处理不同的调用场景。 -> 这两个字段的实现机制基于调用堆栈分析,尽管已经做了各种特殊情况的处理,但在涉及多线程的复杂场景下,依然存在误判的可能。若您发现了相关的可复现BUG,请在Github提交Issue。 +注意,由于`TestableMock`并不依赖(也不希望依赖)任何特定测试框架,因而无法自动识别单个测试用例的结束位置,这使得设置到`TestableTool.MOCK_CONTEXT`变量的参数可能会在同测试类中跨测试用例存在。建议总是在使用后及时使用`MOCK_CONTEXT.clear()`清空上下文,也可将这行语句添加到单元测试框架特定的测试用例结束的统一位置,比如JUnit 5的`@AfterEach`方法。 + +> `TestableTool.MOCK_CONTEXT`变量目前是在测试类内共享的,当单元测试并行运行时,建议请选择`parallel`类型为`classes` 完整代码示例见`java-demo`和`kotlin-demo`示例项目中的`should_able_to_get_source_method_name()`和`should_able_to_get_test_case_name()`测试用例。 diff --git a/testable-agent/pom.xml b/testable-agent/pom.xml index d1bdc02..9eb4eb8 100755 --- a/testable-agent/pom.xml +++ b/testable-agent/pom.xml @@ -6,7 +6,7 @@ com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 ../testable-parent testable-agent diff --git a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java index 038c165..0d8ad31 100644 --- a/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java +++ b/testable-agent/src/main/java/com/alibaba/testable/agent/handler/SourceClassHandler.java @@ -43,11 +43,11 @@ public class SourceClassHandler extends BaseClassHandler { } Set memberInjectMethods = new HashSet(); Set newOperatorInjectMethods = new HashSet(); - for (MethodInfo mi : injectMethods) { - if (mi.getName().equals(ConstPool.CONSTRUCTOR)) { - newOperatorInjectMethods.add(mi); + for (MethodInfo im : injectMethods) { + if (im.getName().equals(ConstPool.CONSTRUCTOR)) { + newOperatorInjectMethods.add(im); } else { - memberInjectMethods.add(mi); + memberInjectMethods.add(im); } } for (MethodNode m : cn.methods) { diff --git a/testable-all/pom.xml b/testable-all/pom.xml index c4b2497..6427f43 100644 --- a/testable-all/pom.xml +++ b/testable-all/pom.xml @@ -6,7 +6,7 @@ com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 ../testable-parent testable-all diff --git a/testable-core/pom.xml b/testable-core/pom.xml index b132361..ae45c2a 100644 --- a/testable-core/pom.xml +++ b/testable-core/pom.xml @@ -6,7 +6,7 @@ com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 ../testable-parent testable-core diff --git a/testable-maven-plugin/pom.xml b/testable-maven-plugin/pom.xml index acfe505..187b918 100644 --- a/testable-maven-plugin/pom.xml +++ b/testable-maven-plugin/pom.xml @@ -6,7 +6,7 @@ com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 ../testable-parent testable-maven-plugin diff --git a/testable-parent/pom.xml b/testable-parent/pom.xml index ff25d80..7ed1f33 100644 --- a/testable-parent/pom.xml +++ b/testable-parent/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 pom testable-parent Unit test enhancement toolkit @@ -42,7 +42,7 @@ 1.6 1.6.8 3.6.0 - 0.4.5 + 0.4.6 diff --git a/testable-processor/pom.xml b/testable-processor/pom.xml index 3ce306c..8313c50 100644 --- a/testable-processor/pom.xml +++ b/testable-processor/pom.xml @@ -6,7 +6,7 @@ com.alibaba.testable testable-parent - 0.4.5 + 0.4.6 ../testable-parent testable-processor