简体   繁体   English

管理Junit测试的测试数据

[英]Managing test data for Junit tests

We are facing one problem in managing test data (xmls which is used to create mock objects). 我们在管理测试数据时遇到了一个问题(xmls用于创建模拟对象)。 The data which we have currently has been evolved over a long period of time. 我们目前的数据已经在很长一段时间内得到了发展。 Each time we add a new functionality or test case we add new data to test that functionality. 每次我们添加新功能或测试用例时,我们都会添加新数据来测试该功能。 Now, the problem is when the business requirement changes the format( like length or format of a variable) or any change which the test data doesn't support , we need to change the entire test data which is 100s of MBs in size. 现在,问题是当业务需求改变格式(如变量的长度或格式)或测试数据不支持的任何更改时,我们需要更改整个测试数据的大小为100的MB。 Could anyone suggest a better method or process to overcome this problem? 有谁能建议一个更好的方法或过程来克服这个问题? Any suggestion would be appreciated. 任何建议将不胜感激。

Personally, I would stay away from creating data for tests case anywhere other then within the test cases. 就个人而言,我会在测试用例之外的任何地方远离为测试用例创建数据。 Instead of creating test data, create data generators that allow for the quick generation of objects within each test case or within each before block. 创建数据生成器而不是创建测试数据,这些数据生成器允许在每个测试用例内或每个块之前快速生成对象。

This has two main advantages: 这有两个主要优点:

  1. It makes the tests much easier to read as the developer can see exactly what objects are being used, and 它使测试更容易阅读,因为开发人员可以准确地看到正在使用的对象,以及
  2. It should greatly cut down on the amount of test data that you need to manage. 它应该大大减少您需要管理的测试数据量。

Reserve test data for things like functional and integration tests and use a tool like DBDeploy to manage that data. 为功能和集成测试保留测试数据,并使用DBDeploy等工具来管理数据。 This data needs to be kept intentionally small. 这些数据需要保持很小的数据。 The use of DBDeploy and DBUnit allows for the database to be cleaned before each test or test suite. 使用DBDeploy和DBUnit允许在每个测试或测试套件之前清理数据库。 This should also limit the amount of data you need as it greatly increases data reuse. 这也应该限制您需要的数据量,因为它大大增加了数据重用。

While this is not a complete solution to your problem, but would definitely help (esp in your case since you have 100s of MBs of data) -- Write tests based on behavior verification instead of data verification . 虽然这不是一个完整的问题解决方案,但肯定会有所帮助(特别是在你的情况下,因为你有100个MB的数据) - 根据行为验证而不是数据验证编写测试。

Martin Fowler has a very good article here Martin Fowler 在这里有一篇非常好的文章

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

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