Once the contract is mined there is very little you can do to change it, you have to be sure that everything works as intended.
There is no substitute for testing. In this tutorial I am going to talk about two types of tests, unit testing and e2e testing (End to End) applied to Ethereum Solidity.
I am going to create a erc20 token (Gtoken).
As with any feature, the first thing to do is to gather the requirements.
requirements
The starting tokens amount is 1000;
When initiated the Owner address is award all the tokens;
It is possible to transfer tokens from one user to the other;
Unit testing
Unit testing is a method where you test a individual unit of code. It focus on classes and classes’ functions. The first two requirements are the best targets for unit testing, the 3th one is a end to end test.
End to end testing (e2e)
End to end testing is “used to test whether the flow of an application is performing as designed from start to finish”(source). the third requirement, to be possible to transfer tokens from one user to the other is is there with e2e testing. The End to end testing will use Javacript.
You should write tests before deploying a contract into the Blockchain. For more information see this tutorials on Developing an ICO/Crowdsale with TDD