mirror of
https://github.com/alibaba/testable-mock.git
synced 2026-08-19 09:43:29 +08:00
doc: describe no unique public constructor error
This commit is contained in:
@@ -62,3 +62,9 @@ This framework will run Android unit tests on a standard JVM virtual machine, wh
|
||||
This problem is caused by the system `Class Path` content is too long, and has nothing to do with `TestableMock`. However, it should be noted that IntelliJ provides two auxiliary solutions: `JAR manifest` and `classpath file`. If `TestableMock` is used in the test, please select `JAR manifest`.
|
||||
|
||||

|
||||
|
||||
#### 10. Getting "no unique public constructor for [xxx]" error with `OmniConstructor`?
|
||||
|
||||
When the `omni.constructor.enhance.enable` configuration is enabled, `TestableMock` will dynamically add a constructor with a parameter of `java.lang.Void` when each class is loaded into memory to avoid the original type constructor exceptions that may be thrown. The above error occurs when some frameworks do not allow multiple constructors for some classes.
|
||||
|
||||
The solution is to add the package path where the error class is located to the `omni.constructor.enhance.pkgPrefix.excludes` configuration, which tell `TestableMock` not to dynamically add constructors to these classes. For details, please refer to the [Global Run Arguments](en-us/doc/javaagent-args.md) document.
|
||||
|
||||
@@ -64,3 +64,9 @@ Kotlin语言中的`String`类型实际上是`kotlin.String`,而非`java.lang.S
|
||||
这个问题是由于系统ClassPath包含太多路径所致,与是否使用`TestableMock`无关。但需要注意的是,IntelliJ提供了两种辅助解决机制:`JAR manifest`和`classpath file`,若测试中使用了`TestableMock`,请选择`JAR manifest`。
|
||||
|
||||

|
||||
|
||||
#### 10. 使用`OmniConstructor`遇到"no unique public constructor for [xxx]"错误?
|
||||
|
||||
当启用`omni.constructor.enhance.enable`配置时,`TestableMock`会在每个类加载进内存时动态添加一个参数为`java.lang.Void`的构造方法,用于避开原类型构造方法里可能抛出的异常。若遇到某些框架不允许类型存在多个构造方法的时候,就会出现上述错误。
|
||||
|
||||
解决办法是将报错类所在的包路径添加到`omni.constructor.enhance.pkgPrefix.excludes`配置中,告知`TestableMock`不要对这些类动态添加构造方法即可。配置方法详见[全局运行参数](zh-cn/doc/javaagent-args.md)文档。
|
||||
|
||||
Reference in New Issue
Block a user