Maven格式化项目中的JUnit测试包私有类 [英] JUnit testing package private class in Maven formatted project

查看:80
本文介绍了Maven格式化项目中的JUnit测试包私有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接口的程序包私有实现,可以通过公共工厂访问该接口中定义的方法.我只是在想,应该如何对该类进行单元测试,因为它不能在包外部访问,还是应该在工厂进行测试?

I have a package private implementation of an Interface, the methods defined in that Interface can be accessed through a public factory. I was just wondering, how should I unit test that class as it cannot be accessed outside the package, or should I be testing it through the factory?

谢谢

-阿比迪

推荐答案

通常的惯例是将类的单元测试与被测类放在同一包中.这样,单元测试就可以访问该类的程序包专用和受保护的方法,从而对其进行测试.

The usual convention is to put the unit test of a class in the same package as the class under test. This allows the unit test to access package-private and protected methods of the class, and thus to test them.

这篇关于Maven格式化项目中的JUnit测试包私有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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