The University of Illinois is developing the IlliniSat-2 bus which uses magnetometers and magnetorquers for attitude determination and control. To validate the attitude determination and control system (ADCS), a hardware-in-loop simulation package (CubeSim) was developed. CubeSim consists of a tri-axial Helmholtz cage driven by a custom power supply. The CubeSim software propagates the satellite's orbit and attitude state and the corresponding Earth magnetic field is output to the Helmholtz cage to be detected by a magnetometer. The satellite's attitude determination software estimates the spacecraft attitude from magnetic field measurements from the magnetometer as well as other sensors simulated in software. The satellite's attitude control program outputs a commanded torque to the control system which is used as an input to CubeSim. CubeSim then propagates the satellite's state and orbit again. This paper describes the setup of CubeSim and demonstrates testing of different magnetic attitude determination and control strategies using CubeSim.