How to deal with the test data in Junit?

后端 未结 5 1261
情书的邮戳
情书的邮戳 2021-01-05 15:13

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

5条回答
  •  隐瞒了意图╮
    2021-01-05 15:41

    When my test data must be an external file - a situation I try to avoid, but can't always - I put it into a reserved test-data directory at the same level as my project, and use getClass().getClassLoader().getResourceAsStream(path) to read it. The test-data directory isn't a requirement, just a convenience. But try to avoid needing to do this; as @philippe points out, it's almost always nicer to have the values hard-coded in the tests, right where you can see them.

提交回复
热议问题