Comments (8)
如果在IDE里面直接运行的话,参考一下常见问题的第6项
https://alibaba.github.io/testable-mock/#/zh-cn/doc/frequently-asked-questions
from testable-mock.
Eclipse 运行需要设置什么吗?访问私有方法报错.
运行单元测试不行,通过 mvn clean package,就可以运行。
from testable-mock.
@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功能的,然后测试就能正常运行了。见下图:
from testable-mock.
@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.
重新验证了一下,发现-processor
参数确实不管用,这个是Javac的参数,在运行配置里会被直接忽略,我先前之所以通过是因为先在命令行做了mvn test-compile
。Eclipse的Java构建是自己实现的,不基于Javac,还没找到可行的配置方法。
目前确定能走通的一种方法是在Eclipse上关闭“Project > Build Automatically”自动构建,然后执行一次mvn clean
,之后手工执行mvn test test-compile
来进行构建,但这样使用起来确实不太优雅,如果我能找到基于Eclipse自身配置的解法再来更新。
from testable-mock.
按照Eclipse官方的Annotation Processor支持机制,操作流程应该如下:
- 在项目目录右键打开
Properties
配置窗口 - 然后在
Java Compiler -> Annotation Processing
配置启用Enable annotation processing
- 最后在
Java Compiler -> Annotation Processing -> Factory Path
配置启用Enable project specific settings
,添加testable-processor-0.4.4.jar
这个Jar包
实际验证并不管用。
from testable-mock.
更新一下进展,Eclipse启用Annotation Processing
依然不生效的原因大概清楚了,是因为Eclipse的编译期注解处理器也是自己实现的,与Javac的标准实现不兼容。这个问题处理起来需要一定时间。
如果确实使用Eclipse IDE,可以先采用PrivateAccessor
工具类的方式进行私有成员访问。
from testable-mock.
IntelliJ里运行单元测试的问题在0.4.5版本中已修复,此Issue讨论的相关问题已更新至文档 https://alibaba.github.io/testable-mock/#/zh-cn/doc/use-in-ide
from testable-mock.
Related Issues (20)
- OmniConstructor工具类,开启了字节码增强,但mock对象时还是会随机偶发报错 HOT 3
- when use MockWith annotation, mockClass not right HOT 2
- 包路径映射后,mock未生效
- Maven package failed due to EnablePrivateAccessProcessor HOT 5
- 建议:建议增加两个快速开始文档 HOT 1
- OmniConstructor.newInstance(RyNormalTask.class) 报错 Failed to invoke constructor HOT 1
- 如何避免mock代码异常提交 HOT 3
- @MockContainer 注解对于继承类的void方法不能正常生效
- 被测试类的方法没有被mock HOT 1
- 使用@RequiredArgsConstructor出现Failed to load ApplicationContext
- 与Jacoco一起使用时,不支持Java17
- 使用OmniConstructor.newInstance()报错 HOT 1
- 从0.7.7升级到0.7.9,启用OmniConstructor的字节码增强模式效率变得非常慢
- 按文档在test里设置jvmArgs报空指针
- 测试service 中调用dao 中继承自mybatis中basemapper通用方法,mock dao层 不生效
- dao层mock 新增 修改 返回int类型接口,启动test报错,类型不匹配,改成Integer,mock不生效
- SpringBoot3中@{argLine} 和 -javaagent不能同时使用
- springboot框架下拦截器中的方法怎么修改
- 一个被测试类可以有个多个Mock类吗?
- javademo为什么使用jacoco覆盖率依然为0?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from testable-mock.