Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OmniConstructor工具类,开启了字节码增强,但mock对象时还是会随机偶发报错 #314

Open
caofanCPU opened this issue Jan 17, 2023 · 3 comments

Comments

@caofanCPU
Copy link

image

JDK
jdk1.8.0_291.jdk

IDEA版本:
IntelliJ IDEA 2022.3.1 (Ultimate Edition)
Build #IU-223.8214.52, built on December 20, 2022

@caofanCPU
Copy link
Author

经过排查,发现testable.properties配置文件不生效
我是使用spock测试框架

配置文件不生效怎么排查呢

@caofanCPU
Copy link
Author

再排查,发现可能是环境上哪里有问题,导致testable-agent无法直接识别出test/resource下的testable.properties配置文件,使用pom指定相对于根路径的path,可以成功

image

@caofanCPU
Copy link
Author

使用的是spock框架,开启了增强omni.constructor.enhance.enable=true
测试用例里使用spock的Mock方法时,会出现报错:构造方法重复

Duplicate method name "" with signature "(Ljava.lang.Void;)V" in class

请问spock对于spock的搭配,具体实践还是new 实际类麽?

附上场景代码

`class OmniConstructorTest extends Specification {

@SpringBean
private SomeServiceClass contractClient = Mock()

@MockDiagnose(LogLevel.VERBOSE)
static class Mock {

}

@Unroll
def "omniConstructor"() {
    def bigDecimal = OmniConstructor.newInstance(BigDecimal.class)
    def date = OmniConstructor.newInstance(Date.class)
    def longNumber = OmniConstructor.newInstance(Long.class)
    def bigInt = OmniConstructor.newInstance(BigInteger.class)

    expect:
    assert 0 == OmniConstructor.newInstance(int.class)
    assert 0L == OmniConstructor.newInstance(Long.class)
    assert "" == OmniConstructor.newInstance(String.class)
    assert LogLevel.DISABLE == OmniConstructor.newInstance(LogLevel.class)
    assert 0.0 == bigDecimal
    assert date.getTime() > 0
    assert longNumber == 0L
    assert bigInt.intValue() == 0
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant