JAVA- unit testing

112 Views Asked by At

i am doing unit testing(Code written by other student) in java using TestNG. Problem is that i am unable to mock the object in code because every function is taking ArrayList of ArrayList(value under arrayList is a object of ArrayList). Please suggest me any tools for mocking or any good method, i tried easyMock and others and had a same problem.

1

There are 1 best solutions below

0
Nathan Hughes On

The design of the code you're testing seems highly suspect but that shouldn't stop you from testing it. Just because you are writing a test doesn't mean you are required to mock everything. You can create the object you need to pass in beforehand, then give it to the method you're testing:

@Test
public void testStuff() {
    List outerList = new ArrayList();
    List innerList = new ArrayList();
    innerList.add("something");
    outerList.add(innerList);
    someObject.crazyMethod(outerList);
}

There needs to be some kind of documentation where your fellow student explains how to call his code so you can know what to pass into it. It shouldn't be your fault if the way he insists on having his objects called is crazy.

I have an answer to another question that talks about when to mock and when not to here.