mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-03-10 09:40:30 +08:00
release version 0.4.6
This commit is contained in:
parent
0f2c889c46
commit
cd7097ded9
@ -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小时内回复并处理
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -12,7 +12,7 @@
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<junit.version>5.6.2</junit.version>
|
||||
<testable.version>0.4.5</testable.version>
|
||||
<testable.version>0.4.6</testable.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -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<KotlinCompile> {
|
||||
|
@ -14,7 +14,7 @@
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<junit.version>5.6.2</junit.version>
|
||||
<testable.version>0.4.5</testable.version>
|
||||
<testable.version>0.4.6</testable.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,7 @@ It is recommended to add a `property` field that identifies the TestableMock ver
|
||||
|
||||
```xml
|
||||
<properties>
|
||||
<testable.version>0.4.5</testable.version>
|
||||
<testable.version>0.4.6</testable.version>
|
||||
</properties>
|
||||
```
|
||||
|
||||
@ -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')
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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)
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
```xml
|
||||
<properties>
|
||||
<testable.version>0.4.5</testable.version>
|
||||
<testable.version>0.4.6</testable.version>
|
||||
</properties>
|
||||
```
|
||||
|
||||
@ -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')
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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()`测试用例。
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<relativePath>../testable-parent</relativePath>
|
||||
</parent>
|
||||
<artifactId>testable-agent</artifactId>
|
||||
|
@ -43,11 +43,11 @@ public class SourceClassHandler extends BaseClassHandler {
|
||||
}
|
||||
Set<MethodInfo> memberInjectMethods = new HashSet<MethodInfo>();
|
||||
Set<MethodInfo> newOperatorInjectMethods = new HashSet<MethodInfo>();
|
||||
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) {
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<relativePath>../testable-parent</relativePath>
|
||||
</parent>
|
||||
<artifactId>testable-all</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<relativePath>../testable-parent</relativePath>
|
||||
</parent>
|
||||
<artifactId>testable-core</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<relativePath>../testable-parent</relativePath>
|
||||
</parent>
|
||||
<artifactId>testable-maven-plugin</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>testable-parent</name>
|
||||
<description>Unit test enhancement toolkit</description>
|
||||
@ -42,7 +42,7 @@
|
||||
<plugin.gpg.version>1.6</plugin.gpg.version>
|
||||
<plugin.staging.version>1.6.8</plugin.staging.version>
|
||||
<plugin.maven.version>3.6.0</plugin.maven.version>
|
||||
<testable.version>0.4.5</testable.version>
|
||||
<testable.version>0.4.6</testable.version>
|
||||
</properties>
|
||||
|
||||
<profiles>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>com.alibaba.testable</groupId>
|
||||
<artifactId>testable-parent</artifactId>
|
||||
<version>0.4.5</version>
|
||||
<version>0.4.6</version>
|
||||
<relativePath>../testable-parent</relativePath>
|
||||
</parent>
|
||||
<artifactId>testable-processor</artifactId>
|
||||
|
Loading…
Reference in New Issue
Block a user