Hi everyone,
I'm having a problem with a JUnit test I've written. I think there should be a simple solution but I can't work out what's wrong. I'm new to using JUnit so any advice would be a big help.
Here's the test class below. At the moment I'm just testing that 3 arraylists are of the correct size (100 elements). The 1st test passes but the 2nd and 3rd fail, with the results saying that they have 200 and 300 elements respectively. So it seems the results of arraylist.size() are accumulating, which is strange because they're in different tet methods.
Ps. I have put println calls in the actual methods being tested and I know they have the right number of elements (all have 100 each).
public class DataBuilderTest
{
DataBuilder db = new DataBuilder();
private int expectedSize = 100;
public DataBuilderTest()
{
}
@BeforeClass
public static void setUpClass() throws Exception
{
System.out.println("** DataBuilder test start");
}
@AfterClass
public static void tearDownClass() throws Exception
{
System.out.println("** DataBuilder test end");
}
@Before
public void setUp()
{
}
@After
public void tearDown()
{
}
@Test
public void testGetCharacters()
{
ArrayList<String> characters = DataBuilder.getCharacters();
assertEquals(expectedSize, characters.size());
}
@Test
public void testGetMeanings()
{
ArrayList<String> meanings = DataBank.getMeanings();
assertEquals(expectedSize, meanings.size());
}
@Test
public void testGetReadings()
{
ArrayList<String> readings = DataBank.getReadings();
assertEquals(expectedSize, readings.size());
}
}
Any ideas what's up with the above test code?