Automatic testing and diagnosis