Junit testing - Actions for every test. How to minimize code?
44 观看
2回复
21 作者的声誉
I really didn't know how to describe it better in the title, but here it is explained:
I want to write tests for a Rest Api. Meaning: I log into the server for every test, run my call and log out. It would be way less code and more efficient, if I could somehow log into the server at the beginning of the test, do all my calls (still in seperate tests though) and then log out.
Is there a smart way to do this?
Thanks for every reply!
作者: Lukas W. 的来源 发布者: 2017 年 12 月 27 日回应 2
0像
149 作者的声誉
Have you looked at annotation tags? i.e. @Before and @After tags
So for example:
@Before
private void loginToServer() throws Exception {
/* Some code to do your login
and some code to do your repetitive tests
}
@Test
private void testEvents() {
//// Your test code
}
@After
private void logoutServer() throws Exception {
/// Code to logout of your server
}
This way your code will always do the Before tag before it runs anything you set in the @Test class. And your @After class will always logout when finished.
作者: mvoase 发布者: 2017 年 12 月 27 日0像
497 作者的声誉
来自类别的问题 :
- unit-testing TDD和BDD之间的主要区别是什么?
- unit-testing 如何测试私有函数或具有私有方法,字段或内部类的类?
- unit-testing Python单元测试在哪里?
- unit-testing 如何模拟内存分配错误
- testing 用户界面测试
- testing 如何测试WPF用户界面?
- testing 用于使用webServices的Curl命令行?
- testing 确定bash中是否存在函数
- junit 你如何断言在JUnit 4测试中抛出某个异常?
- junit 如何在Windows中设置长Java类路径?
- junit 如何在java中对jdbc代码进行单元测试?
- junit 2个JUnit Assert类之间的差异
- server Using node.js as a simple web server
- server Apache2:'AH01630:服务器配置拒绝客户端'
- server 如何为Spring Boot应用程序配置端口
- server 将zmq经销商绑定到多个回复者
- assert 我的程序崩溃时如何自动生成堆栈跟踪
- assert 如何在C / C ++中将assert放入发布版本中