如何在Junit中处理测试数据? [英] How to deal with the test data in Junit?
问题描述
在TDD(测试驱动开发)开发过程中,如何处理测试数据?
假设一个场景,解析一个日志文件以获得所需的列。对于强大的测试,我如何准备测试数据?我是否正确地将这些文件放到测试类文件中?
In TDD(Test Driven Development) development process, how to deal with the test data? Assumption that a scenario, parse a log file to get the needed column. For a strong test, How do I prepare the test data? And is it properly for me locate such files to the test class files?
推荐答案
例如,Maven使用文件夹的约定负责测试数据的结构:
Maven, for example, uses a convention for folder structures that takes care of test data:
src
main
java <-- java source files of main application
resources <-- resource files for application (logger config, etc)
test
java <-- test suites and classes
resources <-- additional resources for testing
如果你使用maven进行构建,你需要将测试资源放在正确的文件夹,如果你的建筑有不同的东西,你可能想要使用这个结构,因为它不仅仅是一个maven惯例,我认为它接近'最佳实践'。
If you use maven for building, you'll want to place the test resources in the right folder, if your building with something different, you may want to use this structure as it is more than just a maven convention, to my opinion it's close to 'best practise'.
这篇关于如何在Junit中处理测试数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!