2011-03-21 15 views
0

このクラスのテストクラスを書く方法。テストクラスを書く方法

パブリッククラスInventoryDe​​tails {

/* Constructor does not do anything */ 

public InventoryDetails(ApexPages.StandardController controller) { 

} 

/* The method getInventory returns an array of inventory objects that meet certain criteria */ 

public Inventory__c[] getInventoryDetails() { 

    Inventory__c [] inventoryList; 

    inventoryList = [select Inventory__c.Rooms_Available__c, Inventory__c.Room_Type__c from Inventory__c]; 

    return inventoryList; 

} 

} いずれかが私にこの質問を教えてください知っていれば。

答えて

0

(することができますが)あなたは、テストのための特別なクラスを記述する必要はありません、シンプルさと減少混乱のために、私たちは特別な静的試験方法を用いて、同じクラスでテストを保つ:

public with sharing class InventoryDetails { 
    public InventoryDetails(ApexPages.StandardController controller) {} 

    public Inventory__c[] getInventoryDetails() { 
     Inventory__c [] inventoryList; 
     inventoryList = [select Inventory__c.Rooms_Available__c, Inventory__c.Room_Type__c from Inventory__c]; 
     return inventoryList; 
    } 

    // ********************************************************* 
    // TESTS 
    static testMethod void test_InventoryDetails() { 
     // replace Object123 with entity name for the 
     // object for which this extension is built 
     // don;t worry about insert o, SF rollbacks all test DMLs 
     Object123 o = new Object123(); 
     insert o; 
     ApexPages.StandardController ctrl = new ApexPages.StandardController(o); 

     InventoryDetails i = new InventoryDetails(o); 
     List<Inventory__c> invs = i.getInventoryDetails(); 
     // do asserts and test and whatever needs to be tested 
    } 
} 
+0

ありがとうございます。しかし、私はこのインベントリ詳細テストクラスを再度表示します。つまり、コンパイルエラー:コンストラクタが定義されていません:[InventoryDe​​tails]。()13行目の35行目で問題を解決してください。 – suman

+0

ああ、私はコードを更新しました。 – mmix

2

一つの利点テストメソッドを含む別のクラスを作成することは、@isTest annotationでマークすることができます。

@isTestアノテーションで定義されたクラスは、すべてのApexスクリプトの組織サイズ制限にはカウントされません。

関連する問題