Apexテスト
Apex 単体テストの開始
- Apex 単体テストにより、Apex コードの品質が高まり、Apex のリリース要件を満たすことができます。
- Apex コードは、Sandbox 環境または開発者組織でのみ記述でき、本番組織では記述できません。
- Apex クラスおよびトリガが期待どおりに機能することを確認できる
- Apex コードの少なくとも 75% がテストでカバーされ
テストスイートの作成および実行
- テストスイートとは、まとめて実行する Apex テストクラスのコレクションです。
- 開発者コンソールで、
もうひとこと
- Test.startTest() Test.stopTest()
Account acct = new Account(Name='Test Account');
insert acct;
Contact c = new Contact(FirstName='Test Account',LastName='INVALIDNAME',AccountId =acct.Id );
Test.startTest();
Database.SaveResult result = Database.insert(c, false);
Test.stopTest();
System.assert(!result.isSuccess());
System.assert(result.getErrors().size() > 0);
System.assertEquals('The Last Name "INVALIDNAME" is not allowed for DML', result.getErrors()[0].getMessage());