check method parameter count

This commit is contained in:
金戟
2021-01-31 15:10:34 +08:00
parent 7029579534
commit 39c788cd02
8 changed files with 117 additions and 33 deletions

View File

@@ -47,7 +47,7 @@ It can be used in combination with [Roboelectric](https://github.com/robolectric
The `Dalvik` and `ART` virtual machines of the Android system use a bytecode system different from the standard JVM, which will affect the normal functionality of `TestableMock`. The `Roboelectric` framework can run Android unit tests on a standard JVM virtual machine, which is much faster than running unit tests through the Android virtual machine. Recently, most Android App unit tests are written with the `Roboelectric` framework.
#### 8. Meet "Attempt to access none-static member in mock method" error during mocking
#### 8. Meet "Attempt to access non-static member in mock method" error during mocking
The current design of `TestableMock` does not allow access to the non-`static` members of the test class in the mock method (because the mock method itself will be dynamically modified to the `static` type during runtime). However, some Java statements include building blocks (like `new ArrayList<String>() {{ append("data"); }}`), lambda expression (like `list.stream().map(i -> i. get)`) and so on, will generate additional member method invocations during compilation, causing mock method execution report above error.

View File

@@ -47,7 +47,7 @@ Kotlin语言中的`String`类型实际上是`kotlin.String`,而非`java.lang.S
Android系统的`Dalvik``ART`虚拟机采用了与标准JVM不同的字节码体系会影响`TestableMock`的正常工作。`Roboelectric`框架能在普通JVM虚拟机上运行Android单元测试其速度比通过Android虚拟机运行单元测试快非常多绝大多数Android App的单元测试都在使用`Roboelectric`框架。
#### 8. 使用Mock时候遇到"Attempt to access none-static member in mock method"错误?
#### 8. 使用Mock时候遇到"Attempt to access non-static member in mock method"错误?
当前`TestableMock`的设计不允许在Mock方法中访问测试类的非`static`成员因为Mock方法自身会在运行期被动态修改为`static`类型。然而有些Java语句包括构造块譬如`new ArrayList<String>() {{ append("data"); }}`)、匿名函数(譬如`list.stream().map(i -> i.get)`等等会在编译过程中生成额外的成员方法调用导致Mock方法执行报错。