GithubHelp home page GithubHelp logo

启动demo报错 about testable-mock HOT 8 CLOSED

alibaba avatar alibaba commented on May 2, 2024
启动demo报错

from testable-mock.

Comments (8)

linfan avatar linfan commented on May 2, 2024

如果在IDE里面直接运行的话,参考一下常见问题的第6项
https://alibaba.github.io/testable-mock/#/zh-cn/doc/frequently-asked-questions

from testable-mock.

xiaolinboy avatar xiaolinboy commented on May 2, 2024

Eclipse 运行需要设置什么吗?访问私有方法报错.
image
运行单元测试不行,通过 mvn clean package,就可以运行。
image

from testable-mock.

linfan avatar linfan commented on May 2, 2024

@xiaolinboy 加这两个配置

  • Program arguments: -processor com.alibaba.testable.processor.EnablePrivateAccessProcessor
  • VM arguments: -ea -javaagent:/Users/flin/.m2/repository/com/alibaba/testable/testable-agent/0.4.4/testable-agent-0.4.4.jar

前一个是针对私有方法访问的,后一个是针对Mock功能的,然后测试就能正常运行了。见下图:

image
image

from testable-mock.

xiaolinboy avatar xiaolinboy commented on May 2, 2024

@linfan
增加VM配置后可以运行单元测试了,但是DemoPrivateAccessTest 是编译错误,怎么让eclipse 能够编译这个类 DemoPrivateAccessTest。

以下是Eclipse配置文件SpringToolSuite4.ini 的信息
-startup
plugins/org.eclipse.equinox.launcher_1.5.700.v20200207-2156.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.1200.v20200508-1552
-vm
D:/Program Files/Java/jdk1.8.0_66/bin
-product
org.springframework.boot.ide.branding.sts4
--launcher.defaultAction
openFile
-vmargs
-ea
-javaagent:E:/temp/.m2/local/repo/com/alibaba/testable/testable-agent/0.4.4/testable-agent-0.4.4.jar
-processor com.alibaba.testable.processor.EnablePrivateAccessProcessor

-Dosgi.requiredJavaVersion=1.8
-javaagent:lombok.jar
-Xloggc:gc.log
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-Xverify:none
-XX:+AggressiveOpts
-XX:CompileThreshold=1000
-XX:+UseStringCache
-XX:+OptimizeStringConcat
-XX:+UseCompressedStrings
-Dosgi.requiredJavaVersion=1.8
-Dosgi.module.lock.timeout=10
-Dorg.eclipse.swt.browser.IEVersion=10001
-Xms1024m
-Xmx1024m
#-XX:+UseG1GC
-XX:+UseStringDeduplication
--add-modules=ALL-SYSTEM

from testable-mock.

linfan avatar linfan commented on May 2, 2024

重新验证了一下,发现-processor参数确实不管用,这个是Javac的参数,在运行配置里会被直接忽略,我先前之所以通过是因为先在命令行做了mvn test-compile。Eclipse的Java构建是自己实现的,不基于Javac,还没找到可行的配置方法。
目前确定能走通的一种方法是在Eclipse上关闭“Project > Build Automatically”自动构建,然后执行一次mvn clean,之后手工执行mvn test test-compile来进行构建,但这样使用起来确实不太优雅,如果我能找到基于Eclipse自身配置的解法再来更新。

from testable-mock.

linfan avatar linfan commented on May 2, 2024

按照Eclipse官方的Annotation Processor支持机制,操作流程应该如下:

  1. 在项目目录右键打开Properties配置窗口
  2. 然后在Java Compiler -> Annotation Processing配置启用Enable annotation processing
  3. 最后在Java Compiler -> Annotation Processing -> Factory Path配置启用Enable project specific settings,添加testable-processor-0.4.4.jar这个Jar包

实际验证并不管用。

from testable-mock.

linfan avatar linfan commented on May 2, 2024

更新一下进展,Eclipse启用Annotation Processing依然不生效的原因大概清楚了,是因为Eclipse的编译期注解处理器也是自己实现的,与Javac的标准实现不兼容。这个问题处理起来需要一定时间。

如果确实使用Eclipse IDE,可以先采用PrivateAccessor工具类的方式进行私有成员访问。

from testable-mock.

linfan avatar linfan commented on May 2, 2024

IntelliJ里运行单元测试的问题在0.4.5版本中已修复,此Issue讨论的相关问题已更新至文档 https://alibaba.github.io/testable-mock/#/zh-cn/doc/use-in-ide

from testable-mock.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.