在一个参数化类(junit)中创建多个参数集 [英] Create multiple parameter sets in one parameterized class (junit)

查看:419
本文介绍了在一个参数化类(junit)中创建多个参数集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我必须为每个要使用多个不同输入进行测试的方法创建参数化测试类。有没有办法在一个文件中一起添加?



现在有 CalculatorTestAdd.java 有一套用于检查 Add()函数是否正常工作的参数。我是否有可能将此设置连接到 Add()函数并创建一个用于 Subtract()的附加设置方法并在同一测试类中添加此方法,从而生成一个名为 CalculatorTest.java 的文件?

解决方案

是的。你不需要做什么特别的事。对于参数的每组值,每个@Test方法运行一次,因此只需要一个方法测试add(),另一个方法测试减去()。



<我还要补充一点,指明这一要求的人是误入歧途的。 为所有情况规定某些设计模式几乎没有价值 - 也可以雇用经过培训的猴子。


Currently I have to create a parameterized test class for every method that I want to test with several different inputs. Is there a way to add this together in one file?

Right now there's CalculatorTestAdd.java which has a set of parameters that are used to check if the Add() function works properly. Is there a possbility for me to 'connect' this set to the Add() function and create an additional set meant for the Subtract() method and add this method in the same test class, resulting in one file called CalculatorTest.java?

解决方案

Yes. There's nothing special you have to do. For every set of value(s) of the parameters, each @Test method is run once, so just have one method test add() and another method test subtract().

May I also add that the person who is dictating this requirement is misguided. There is little value in dictating certain design patterns "for all cases" - might as well hire trained monkeys.

这篇关于在一个参数化类(junit)中创建多个参数集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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