alibaba / testable-mock

换种思路写Mock,让单元测试更简单
https://alibaba.github.io/testable-mock/
MIT License
1.83k stars 310 forks source link

Fixed a flaky test in core.tool.OmniAccessorTest #223

Closed Augustine-C closed 3 years ago

Augustine-C commented 3 years ago

should_generate_member_index in this test is flaky since the method java.lang.Class.getDeclaredFields is non-deterministic, and GetDeclaredFilelds is ultimately used in the com.alibaba.testable.core.util.TypeUtil.getAllFields I converted the result to a HashSet to avoid ordering issues, so the specific ordering of the fields would not affect the result. I think this change can prevent test failure due to future changes in the JVM.

这个测试里的should_generate_member_index是不稳定的。原因是在 com.alibaba.testable.core.util.TypeUtil.getAllFields 使用了java.lang.Class.getDeclaredFields。而GetDeclaredFilelds的结果是非确定的。未来JVM的改变可能这会影响这个测试的结果(返回的顺序可能会改变。)用HashSet去比较结果可以避免相关的问题。

CLAassistant commented 3 years ago

CLA assistant check
All committers have signed the CLA.

linfan commented 3 years ago

thanks for remind : )