为什么要公开定义 Junit 中的测试方法? [英] Why should Test methods in Junit be defined public?

查看:21
本文介绍了为什么要公开定义 Junit 中的测试方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览 junit 测试的文档,但无法理解将测试定义为公共测试的必要性.有人可以分享一些关于此的信息吗?

I was going through the documentation for junit tests but am unable to understand the need for defining tests as public.Could anyone share some info on this?

我阅读了 https://github.com/junit-team/junit/blob/master/src/main/java/org/junit/Test.java

但还是不清楚原因.

我的意思是为什么我不能写一些东西

With is I meant why can't I write something as

@Test
private void testAdd(){ }

推荐答案

JUnit 框架从测试类外部调用测试方法.如果您的测试方法是私有的,它将无法做到这一点.

The JUnit framework calls your test methods from outside your test class. If your test methods are private, it won't be able to do that.

这篇关于为什么要公开定义 Junit 中的测试方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆