suman
suman

Reputation: 143

how to write testclass

how to write test class for this class.

public class InventoryDetails {

 /* 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;

}

} if any one know please tell me this question .

Upvotes: 0

Views: 3655

Answers (2)

Daniel Ballinger
Daniel Ballinger

Reputation: 13537

One advantage of creating a separate class to contain the test methods is that you can mark it with the @isTest annotation.

Classes defined with the @isTest annotation do not count against the organization size limit for all Apex scripts.

Upvotes: 2

mmix
mmix

Reputation: 6278

you don't need to write a special class for testing (though you can), for simplicity and reduced clutter we keep tests in the same class using a special static test method:

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
    }
}

Upvotes: 0

Related Questions