java - 为什么 jUnit 测试必须公开?
问题描述
当我尝试运行如下编写的测试时:
@Test
private void testGet() {
assertTrue(true);
}
我收到以下异常 -java.lang.Exception: Method testGet() should be public
为什么私有方法不能作为单元测试执行?
解决方案
它不能是私有的,但不必是公开的。它可以是默认访问方法。它不能是私有方法,因为该方法必须由 junit 框架从类外部调用。
推荐阅读
- modelica - 翻译时出现 Dymola 错误消息:“Dymola 中的未知内部错误”
- c++ - Boost program_options 解析枚举位掩码
- flutter - 从设备加载视频文件作为`ByteData`颤动
- neural-network - 了解 YOLO 网络的此图
- angular - 使用角度提交对象数组中选定的复选框项目
- ruby-on-rails - Rails 应用程序在生产数据时在所有资源的索引页面上崩溃,但在本地开发环境中完美运行
- java - Java Runnable 作为参数评估
- c# - 缓存键的类或结构
- c# - 有官方的 Tree C# 实现吗?
- powerbi - Power bi 中随时间推移的销售可视化