简体   繁体   English

Junit Automation测试和某些测试需要许多不同的输入

[英]Junit Automation test with some tests requires many different inputs

I am quite new to Junit, I am currently trying to test out some APIs corresponding to a simple UI with many checkboxes and a couple textfields. 我对Junit还是很陌生,我目前正在尝试测试一些与具有多个复选框和几个文本字段的简单UI相对应的API。

what I have in mind now is to write something with the following structure: 我现在想到的是编写具有以下结构的内容:

testButtonOne() testButtonOne()

testButtonTwo() testButtonTwo()

. . .

testButtonTen() testButtonTen()

testCheckboxOne() with many inputs such as space, invalid char, very long string etc testCheckboxOne()具有许多输入,例如空格,无效字符,非常长的字符串等

testCheckboxTwo() with many inputs such as space, invalid char, very long string etc testCheckboxTwo()具有许多输入,例如空格,无效字符,非常长的字符串等

I have tried to write the test in two files, one being single runs and one being parameterized runs, but the problem is that I have to write @BeforeClass @Before @After twice, so I am wondering what would be a better way to write test like this. 我尝试将测试写在两个文件中,一个是单次运行,一个是参数化运行,但是问题是我必须两次编写@BeforeClass @Before @After,所以我想知道哪种更好的书写方式像这样测试。

You can look here: Testing GUI with JUnit 您可以在此处查看: 使用JUnit测试GUI

The main idea is that it is preferred to decouple GUI from business logic and other layers. 主要思想是,最好将GUI与业务逻辑和其他层分离。 In this way GUI layer will contain only GUI specific code, so testing will become easier and it's value will decrease. 这样,GUI层将仅包含GUI特定的代码,因此测试将变得更加容易,并且其价值将降低。 That way you can mock your services in GUI class and just verify, for example, that if you enter some text in EditBox than it's value will go as a parameter to specific service call (in this case I don't think you'll need to write parametrized unit tests), and then you can test service layer separately. 这样,您可以在GUI类中模拟您的服务,并仅验证,例如,如果您在EditBox中输入一些文本,则其值将作为特定服务调用的参数(在这种情况下,我认为您不需要(编写参数化的单元测试),然后可以分别测试服务层。 You can have your validation service, and test it separately as well. 您可以拥有验证服务,也可以分别对其进行测试。 Using such approach tests usually become cleaner and more specific, not so broad, which is the idea laying behind unit tests. 使用这种方法测试通常会变得更干净,更具体,而不是那么广泛,这就是单元测试背后的想法。

If you still need parametrized unit tests for testing GUI, you can have both parametrized and non-parametrized tests, grouped in nested classes of one test class as described here: https://stackoverflow.com/a/28203229/9329760 如果您仍然需要参数化的单元测试来测试GUI,则可以将参数化和非参数化测试按一个测试类的嵌套类分组,如下所示: https : //stackoverflow.com/a/28203229/9329760

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

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