JUnit Best Practice: Different Fixtures for each @Test

Posted by Juri Glass on Stack Overflow See other posts from Stack Overflow or by Juri Glass
Published on 2010-05-03T15:18:02Z Indexed on 2010/05/28 19:22 UTC
Read the original article Hit count: 446

Filed under:
|
|

Hi

I understand that there are @Before and @BeforeClass, which are used to define fixtures for the @Test's. But what should I use if I need different fixtures for each @Test?

  • Should I define the fixture in the @Test?
  • Should I create a test class for each @Test?

I am asking for the best practices here, since both solutions aren't clean in my opinion. With the first solution, I would test the initialization code. And with the second solution I would break the "one test class for each class" pattern.

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about junit