Salesforceでは、sandbox(開発環境)で作成されたApexクラスに対して、テストクラスが必要であり、かつ、テストで75%以上のカバレッジでの合格が必要です。それに達しないと・・・本番環境へのリリースがNGになってしまう。

public class myClass {
  static testMethod void myTest() {
    Account a = new Account(name='foo');
    insert a;
    System.assertEquals('foo', [select name from Account where id=:a.id].name);
    System.assertEquals(1, [select count() from Account where id=:a.id]);
    try {
      delete a;
      Foo.myMethod(a); //call some method
    } catch (DmlException e) {
      System.assert(false);  // assert that we should never get here
    }
  }
}

System.assert() メソッドを使用してコードの動作をチェックする。