使用 JUnit 测试 GUI
嗯,我们都知道测试驱动开发。我需要编写一个基于 GUI 的库,但说实话,我总是忽略测试。为大学等做过 JUnit,但我们从未比通常的“实现列表并测试它”更深入。
因此,由于我不想为这些功能编写上千个应用程序,所以我想知道使用 Scala 和 JUnit 进行基于 GUI 的库测试的“专业”方法是什么?
感谢您的聆听。
Well, we all know test-driven development. I'd need to write a GUI-based library, but to be honest, I always neglected the testing. Did JUnit for university and such, but we never got any deeper than the usual "Implement a list and test it."
So, since I don't want to write a thousand applications for the features, I'd like to know, what's the "professional" approach to GUI-based library testing with Scala and JUnit?
Thanks for listening.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将表示层与其他层分开。
保持表示层尽可能薄,以便理论上可以在给定模式的中间人内进行测试; MVC、MVVM 等...
一旦您开始将表示层与底层逻辑结合起来,您的测试将成为维护和执行的噩梦。
在彻底测试模型/视图模型/控制器等结束时...测试表示层通常会失去其高度重视的价值。它还有价值吗?是的……但是回报大大减少了。
这些概念适用于许多框架/语言。一旦掌握了这种理解,给定框架/语言的技术优势就会自然显现出来。不过,不要依赖框架/语言来回答这个问题。框架/语言绝对可以以更友好的方式提供关注点分离,但是关注点分离始终处于任何类型测试的最前沿;包括图形用户界面。
Separate your Presentation layer from everything else.
Keep the Presentation layer as thin as possible so that testing can in theory take place within a middle-man of a given pattern; MVC, MVVM, etc...
The moment you begin to couple the Presentation layer with underlying logic your testing will become a nightmare to maintain as well as execute.
At the end of thoroughly testing your Models/ViewModels/Controllers, etc...testing the Presentation layer can often times lose its highly regarded value. Is it still valuable? Yes...but the return has diminished considerably.
These concepts apply to many frameworks/languages. Once you grasp this understanding the technological benefits of a given framework/language will surface naturally. Do not rely on the framework/language to answer this though. A framework/language can definitely lend itself to provide separation of concerns in a much more friendly manner however the separation of concerns is and has always been at the forefront of any type of testing; GUI included.
阅读《测试驱动实用 TDD》和《面向 Java 开发人员的验收 TDD》一书。
它涵盖了如何对 Swing 应用程序进行单元测试的基础知识以及一些 TDD 技术。
我还没有读完这本书,所以我不知道它是否涵盖了 Scala,但我强烈推荐这本书(已经)!
一些个人注意事项:如果您想要采取行动,请跳过第一章,然后返回到第一章。
它涵盖了“一般如何开始使用 TDD”
测试驱动书籍链接
Read the book Test Driven a practical TDD and acceptance TDD for java developpers.
It covers the basics on how to unit-test Swing Applications and also some TDD techniques.
I haven't finished the book so i don't know if it covers Scala but i highly recommend this book (already)!
Some personal note : if you want action skip chapter one but return back to it.
It covers the "How to start using TDD in general"
Test Driven book link