简体   繁体   English

属性文件中的单元测试值

[英]unit test values in property file

I have some values in property files that are integers. 我在属性文件中有一些整数值。 Should I write a unit test to check if they are integers? 我应该编写一个单元测试来检查它们是否为整数? If yes how do we accomplish this. 如果是,我们如何做到这一点。 I am not loading the properties into variables. 我没有将属性加载到变量中。 Simply using them directly where required 只需在需要的地方直接直接使用它们

Unit testing is for testing your artifacts (stuff you produce as part of your application/product), not your configuration. 单元测试用于测试工件(作为应用程序/产品的一部分生产的产品),而不是配置。 If the properties file is something that can change outside of your control, the correct thing to do is to check it on use. 如果属性文件是可以在控件之外更改的文件,则正确的做法是在使用时对其进行检查。

In other words, you should have your code check that the properties are integers and then unit-test that code to ensure it correctly imports integers and rejects everything else (floating point, integers with trailing rubbish, non-numeric strings, empty strings and so on). 换句话说,您应该让您的代码检查属性是否为整数,然后对该代码进行单元测试,以确保其正确导入整数并拒绝其他所有内容(浮点数,带尾随垃圾的整数,非数字字符串,空字符串等等。上)。

Unit testing is not for properties files. 单元测试不适用于属性文件。 The proper way to handle bad values in your properties file is with RuntimeExceptions or Errors in the code where they are used 处理属性文件中错误值的正确方法是使用RuntimeExceptions或Errors(在使用错误代码的地方)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM