简体   繁体   English

JUNIT测试使用哪种结构?

[英]Which structure to use with JUNIT test?

I have a Number of tests. 我有一些测试。 Each test contains different commands verify() and command(). 每个测试包含不同的命令verify()和command()。 The order and number of times I need to check these vary though depending on the test. 根据测试,我需要检查这些的顺序和次数会有所不同。 How can I structure this in a convenient way. 我怎样才能以方便的方式构建它。 I have been playing with Suites and Categories but can´t find a good solution. 我一直在玩套房和类别,但无法找到一个好的解决方案。 in the JUNIT GUI I would like to see the Testname and bellow it the teststeps command or verify. 在JUNIT GUI中,我希望看到Testname,然后将它命名为teststeps命令或验证。 Any ideas? 有任何想法吗?

I have found that with maven and modern IDEs, the usefulness of test suites is not all that apparent. 我发现使用maven和现代IDE,测试套件的实用性并不是那么明显。

Maven will run all your tests by default; Maven默认会运行所有测试; and any IDE will allow you to run all your tests or select tests to run, by package, for example. 例如,任何IDE都允许您运行所有测试或选择要运行的测试。 I generally find that creating tests classes within different packages is all the organization I every really utilize. 我通常发现在不同的包中创建测试类是我真正使用的所有组织。

It worries me that you say the "order and number" of times you need to test vary. 它让我担心你说你需要测试的“顺序和数量”有所不同。 I am not clear on exactly what you mean, but if you mean that in order for a test to pass, it is dependent on the order (and times) that other tests execute, then you need to re-architecture your tests. 我不清楚你究竟是什么意思,但如果你的意思是为了让测试通过,它取决于其他测试执行的顺序(和时间),那么你需要重新构建你的测试。 (Particularly in the case of unit tests.) (特别是在单元测试的情况下。)

No test should ever depend on another test. 没有测试应该依赖于另一个测试。 Execution order is not guaranteed, and may execute differently in different environments, or could even be executed in parallel. 不保证执行顺序,并且可以在不同环境中以不同方式执行,或者甚至可以并行执行。

Look at @Before, @After, @BeforeClass, @AfterClass ( http://junit.sourceforge.net/doc/faq/faq.htm#organize_3 ) for more info on initialization of tests. 有关初始化测试的更多信息,请查看@Before,@ After,@ BeforeClass,@ AfterClass( http://junit.sourceforge.net/doc/faq/faq.htm#organize_3 )。 I'm not sure if that is the solution to your problem, though. 不过,我不确定这是否是解决问题的方法。

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

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