The main inspiration for this project came from a need to test 18650 cells salvaged from discarded laptop batteries. The desired uses eventually expanded to testing current output limits of various AC adapters, as well as portable USB batteries and USB car chargers.
We can test the capacity of a battery by drawing a specific current and timing how long until the battery is depleted. While it is possible to test batteries by discharging them through a resistor, for example, the current would drop as the battery voltage drops because of Ohm's law. It would be much more convenient if the current draw was constant, independent of the supply voltage.
We can achieve this by adding some more circuitry and creating a feedback loop. A MOSFET is used as a variable resistor, controlled by an op-amp. A reference voltage sets the desired current, while a current shunt/sensor provides feedback. The op-amp uses the feedback to control the MOSFET's resistance. This way, we can stabilize the current draw even if the voltage is changing. The overall design is similar to many other electronic load circuits (see EEVblog, Kerry Wong 1, Kerry Wong 2, Mightwatt).