Newer Version Available
compileAndTest()
単一のコールで Apex をコンパイルおよびテストします。
構文
1CompileAndTestResult[] = compileAndTest(CompileAndTestRequest request);使用方法
このコールを使用して、1 つのコールで指定した Apex にコンパイルとテストの両方を実行します。本番組織 (Developer Edition または Sandbox Edition ではない) は、compileClasses() または compileTriggers() の代わりにこのコールを使用する必要があります。
このコールは、DebuggingHeader と SessionHeader をサポートしています。API の SOAP ヘッダーの詳細は、『SOAP API 開発者ガイド』を参照してください。
指定されたすべてのテストに合格する必要があります。合格しない場合、データはデータベースに保存されません。このコールが本番組織で呼び出されると、CompileAndTestRequest の RunTestsRequest プロパティは無視され、組織で定義されたすべての単体テストが実行されます。これらのテストに合格する必要があります。
サンプルコード —Java
次の例では、checkOnly を true に設定して、このクラスのコンパイルおよびテストを実行するが、クラスがデータベースに保存されないようにします。
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17{
18 CompileAndTestRequest request;
19 CompileAndTestResult result = null;
20
21 String triggerBody = "trigger t1 on Account (before insert){ " +
22 " for(Account a:Trigger.new){ " +
23 " a.description = 't1_UPDATE';}" +
24 "}";
25
26 String testClassBody = "@isTest private class TestT1{" +
27 " // Test for the trigger" +
28 " public static testmethod void test1(){" +
29 " Account a = new Account(name='TEST');" +
30 " insert(a);" +
31 " a = [select id,description from Account where id=:a.id];" +
32 " System.assert(a.description.contains('t1_UPDATE'));" +
33 " }" +
34 " // Test for the class" +
35 " public static testmethod void test2(){" +
36 " String s = C1.method1();" +
37 " System.assert(s=='HELLO');" +
38 " }" +
39 "}";
40
41 String classBody = "public class C1{" +
42 " public static String s ='HELLO';" +
43 " public static String method1(){" +
44 " return(s);" +
45 " }" +
46 "}";
47
48 request = new CompileAndTestRequest();
49
50 request.setClasses(new String[]{classBody, testClassBody});
51 request.setTriggers(new String[]{triggerBody});
52 request.setCheckOnly(true);
53
54 try {
55 result = apexBinding.compileAndTest(request);
56 } catch (RemoteException e) {
57 System.out.println("An unexpected error occurred: " + e.getMessage());
58 }
59 assert (result.isSuccess());
60}引数
| 名前 | 型 | 説明 |
|---|---|---|
| request | CompileAndTestRequest | Apex およびこの要求に設定する必要のある項目の値を含む要求。 |