diff --git a/demo/java-demo/build.gradle b/demo/java-demo/build.gradle
index e087fa7..bce4c00 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.2')
- testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.2')
+ testImplementation('com.alibaba.testable:testable-all:0.4.3')
+ testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.3')
}
test {
diff --git a/demo/java-demo/pom.xml b/demo/java-demo/pom.xml
index ad1831f..3f5530f 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.2
+ 0.4.3
diff --git a/demo/kotlin-demo/build.gradle.kts b/demo/kotlin-demo/build.gradle.kts
index f049b6c..51e59b9 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.2")
- testAnnotationProcessor("com.alibaba.testable:testable-processor:0.4.2")
+ testImplementation("com.alibaba.testable:testable-all:0.4.3")
+ testAnnotationProcessor("com.alibaba.testable:testable-processor:0.4.3")
}
tasks.withType {
diff --git a/demo/kotlin-demo/pom.xml b/demo/kotlin-demo/pom.xml
index bbec545..b54c359 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.2
+ 0.4.3
diff --git a/docs/zh-cn/doc/private-accessor.md b/docs/zh-cn/doc/private-accessor.md
index d429f2d..387c140 100644
--- a/docs/zh-cn/doc/private-accessor.md
+++ b/docs/zh-cn/doc/private-accessor.md
@@ -3,16 +3,16 @@
如今关于私有方法是否应该做单元测试的争论正逐渐消停,开发者的普遍实践已经给出事实答案。通过公有方法间接测私有方法在很多情况下难以进行,开发者们更愿意通过修改方法可见性的办法来让原本私有的方法在测试用例中变得可测。
-此外,在单元测试中时常会需要对被测对象进行特定的成员字段初始化,但有时由于被测类的构造方法限制,使得无法便捷的对这些字段进行赋值。那么,能否在不破坏被测类型封装的情况下,允许单元测试用例内的代码直接访问被测类的私有方法和成员变量呢?TestableMock提供了两种简单的解决方案。
+此外,在单元测试中时常会需要对被测对象进行特定的成员字段初始化,但有时由于被测类的构造方法限制,使得无法便捷的对这些字段进行赋值。那么,能否在不破坏被测类型封装的情况下,允许单元测试用例内的代码直接访问被测类的私有方法和成员字段呢?TestableMock提供了两种简单的解决方案。
### 方法一:使用`@EnablePrivateAccess`注解
只需为测试类添加`@EnablePrivateAccess`注解,即可在测试用例中获得以下增强能力:
-- 调用被测类的私有方法
-- 读取被测类的私有成员
-- 修改被测类的私有成员
-- 修改被测类的常量成员(使用final修饰的成员)
+- 调用被测类的私有方法(包括静态方法)
+- 读取被测类的私有字段(包括静态字段)
+- 修改被测类的私有字段(包括静态字段)
+- 修改被测类的常量字段(使用final修饰的字段,包括静态字段)
访问和修改私有、常量成员时,IDE可能会提示语法有误,但编译器将能够正常运行测试。(使用编译期代码增强,目前仅实现了Java语言的适配)
@@ -24,11 +24,11 @@
这个类提供了6个静态方法:
-- `PrivateAccessor.get(被测对象, "私有字段名")` ➜ 读取被测类的私有成员
-- `PrivateAccessor.set(被测对象, "私有字段名", 新的值)` ➜ 修改被测类的私有成员(或常量成员)
+- `PrivateAccessor.get(被测对象, "私有字段名")` ➜ 读取被测类的私有字段
+- `PrivateAccessor.set(被测对象, "私有字段名", 新的值)` ➜ 修改被测类的私有字段(或常量字段)
- `PrivateAccessor.invoke(被测对象, "私有方法名", 调用参数..)` ➜ 调用被测类的私有方法
-- `PrivateAccessor.getStatic(被测类型, "私有字段名")` ➜ 读取被测类的**静态**私有成员
-- `PrivateAccessor.setStatic(被测类型, "私有字段名", 新的值)` ➜ 修改被测类的**静态**私有成员(或**静态**常量成员)
-- `PrivateAccessor.invokeStatic(被测类型, "私有方法名", 调用参数..)` ➜ 调用被测类的**静态**私有方法
+- `PrivateAccessor.getStatic(被测类型, "私有静态字段名")` ➜ 读取被测类的**静态**私有字段
+- `PrivateAccessor.setStatic(被测类型, "私有静态字段名", 新的值)` ➜ 修改被测类的**静态**私有字段(或**静态**常量字段)
+- `PrivateAccessor.invokeStatic(被测类型, "私有静态方法名", 调用参数..)` ➜ 调用被测类的**静态**私有方法
详见`java-demo`和`kotlin-demo`示例项目`DemoPrivateAccessTest`测试类中的用例。
diff --git a/docs/zh-cn/doc/release-note.md b/docs/zh-cn/doc/release-note.md
index ebfdaeb..1db2f94 100644
--- a/docs/zh-cn/doc/release-note.md
+++ b/docs/zh-cn/doc/release-note.md
@@ -1,5 +1,8 @@
# Release Note
+## 0.4.3
+- support static private member access
+
## 0.4.2
- support change javaagent global log level via maven plugin
- fix an issue of duplicate test class injection
diff --git a/docs/zh-cn/doc/setup.md b/docs/zh-cn/doc/setup.md
index a56697e..16d6d1b 100644
--- a/docs/zh-cn/doc/setup.md
+++ b/docs/zh-cn/doc/setup.md
@@ -15,7 +15,7 @@
```xml
- 0.4.2
+ 0.4.3
```
@@ -62,8 +62,8 @@
```groovy
dependencies {
- testImplementation('com.alibaba.testable:testable-all:0.4.2')
- testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.2')
+ testImplementation('com.alibaba.testable:testable-all:0.4.3')
+ testAnnotationProcessor('com.alibaba.testable:testable-processor:0.4.3')
}
```
diff --git a/testable-agent/pom.xml b/testable-agent/pom.xml
index 106c813..54670ec 100755
--- a/testable-agent/pom.xml
+++ b/testable-agent/pom.xml
@@ -6,7 +6,7 @@
com.alibaba.testable
testable-parent
- 0.4.2
+ 0.4.3
../testable-parent
testable-agent
diff --git a/testable-all/pom.xml b/testable-all/pom.xml
index 2a79e21..3211145 100644
--- a/testable-all/pom.xml
+++ b/testable-all/pom.xml
@@ -6,7 +6,7 @@
com.alibaba.testable
testable-parent
- 0.4.2
+ 0.4.3
../testable-parent
testable-all
diff --git a/testable-core/pom.xml b/testable-core/pom.xml
index 58f6c72..f5334e4 100644
--- a/testable-core/pom.xml
+++ b/testable-core/pom.xml
@@ -6,7 +6,7 @@
com.alibaba.testable
testable-parent
- 0.4.2
+ 0.4.3
../testable-parent
testable-core
diff --git a/testable-maven-plugin/pom.xml b/testable-maven-plugin/pom.xml
index 0a26712..ba4758a 100644
--- a/testable-maven-plugin/pom.xml
+++ b/testable-maven-plugin/pom.xml
@@ -6,7 +6,7 @@
com.alibaba.testable
testable-parent
- 0.4.2
+ 0.4.3
../testable-parent
testable-maven-plugin
diff --git a/testable-parent/pom.xml b/testable-parent/pom.xml
index 6901409..27f015d 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.2
+ 0.4.3
pom
testable-parent
Unit test enhancement toolkit
@@ -42,7 +42,7 @@
1.6
1.6.8
3.6.0
- 0.4.2
+ 0.4.3
diff --git a/testable-processor/pom.xml b/testable-processor/pom.xml
index febb42e..ef34bc7 100644
--- a/testable-processor/pom.xml
+++ b/testable-processor/pom.xml
@@ -6,7 +6,7 @@
com.alibaba.testable
testable-parent
- 0.4.2
+ 0.4.3
../testable-parent
testable-processor