vendredi 21 août 2015

How do I testing large complex code?

I have a legacy code that contains little more than a 8700 lines with each method on average around 200-300 lines long. I was wondering how am I able to cover most of those code even to get an output of a successful result.

For example:

    public class Aviation implements FlightStruct, FlightSystem extends Vehicles {
    ...var decoration...
    ...override method definitions...

    public controls aviation(Flight request, Flight destination, Flight target) {

    FlightResponse flightResponse = new FlightResponse();

    flightResponse.speed = target.speed;
    angularVel.calculate(greatCircle.flightResponse.speed);
    _readVelData();
    if (vel.circular.velocity <= 10000) {
    for(countryName : country) {
    calculateArrivalTime();
    _readFuel();
    if(fuel.limit < pwi.percent*100) {
           createShortPathLandingPoint(Path newDestination, Register checkPoint);
       }
    }
}
    private eqiptment company(String name, Vendor vendor) {
    ....calculate equiptment stuff that calls bunch of private methods
    }

 ...alot more method here
    }
}

I was wondering how should I go about to unit test these kind of code? I have attempted to stubb data but the inner method is too complicated to walk through. Usually one method calls down multiple layers of sub methods. For example.... the fuel class calls _readfuel and in _readfuel it calls destinationCheckPoint, flightWayPoint, flightSpeedCalc...then in each of those sub method it calls its own sub method. (ex. flightWaypoint calls calculateWayPoint, angVelocity, speedLimit, ....) Overall I do not think this is doable by stubbing the data because finding the right data is difficult. Then My second option was to use Mockito to mock the method / classes. Which sounds more reasonable to do, but again I encounter where there are multiple sub method which are private...and mockito cannot mock the private method. I then attempted to use PowerMockito to mock the private method it work for a few thousand lines and there was something like this:

while (!report.successful && !telCList.isEmpty()) {
...
report.wayPoint = update.assignWayPoint(wayPointList); //null point exception
...

where the update was null and few hundred lines above it was declared

 UpdateGateWay update = setDestinationWayPoint(distance, speed, altitude);

setDestinationWayPoint is a private method and I use powerMockito to mock the behavior I have also returned the value as part of the stub. but when it get called below it become null.

I pretty much give up at this point. I was wondering if there would be more reasonable way to do this type of testing....

Aucun commentaire:

Enregistrer un commentaire