What is the purpose of flutter testing?
Flutter is a phenomenon that can occur when a structure is subjected to aerodynamic forces. It occurs not only in aircraft but also for example in buildings, power lines, road signs and bridges. Flutter is an oscillation caused by interaction of aerodynamic forces, structural elasticity and inertial effects. 

Perhaps the best known example of flutter is the bridge over the Tacoma Narrows ('Gallopin' Gertie')  that collapsed due to flutter in gale force winds. 



Flutter in aircraft causes the wings and / or stabilizers to oscillate. 
When the airspeed increases the energy added in each oscillation to the structure by the aerodynamic forces increases. At some speed the damping of the structure may be insufficient to absorb the energy increase from the aerodynamic loads and the amplitude of the harmonic oscillations will grow until the structure breaks. 

A flutter test is performed to determine what speed flutter occurs yet is still damped. Theoretically an aircraft should be able to stay structurally intact up to the design dive speed ($V_d$) which is at least 1.4 times the design cruise speed. In flight tests, the $V_d$ is not always demonstrated as this is very risky since there would not be any margin from breaking up. The maximum speed is slowly increased in subsequent flight tests with careful data analyses in between up to a point where the test team decides that it is no longer safe to continue. This establishes the maximum demonstrated dive speed ($V_{df}$); the published maximum operating speed ($V_{mo}$) and never-exceed speed ($V_{ne}$) are well below $V_{df}$ to give margin from disaster. 

This video shows flutter in a Hawker 800. The incident occurred not during testing but was caused by inadequate fitting of the ailerons(FAA PDF).