function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rawiswarrawiswar 

how to test with a separate test class

i now have a compiled class with a few inner classes.
what should i do to test all the classes if I want my test methods in a separate class?
would it be enough for salesforce to accept and deploy the classes if the testmethods just about create an object of the classes? (i know it is a yucky thing to do; just want to know the limits).
would i need to test each inner class or is it enough to test just the outer class?
how is this 75% know to force.com ... is each method being counted as an entity and 75% of entities being the requirement?
Thanks


Message Edited by rawiswar on 12-08-2008 02:18 PM
mikefmikef
you can have your testMethods in a different class, just make sure you select the test class when you deploy.
prageethprageeth
Writing test methods in the same class is not a good habit. It affects to the maximum apex code size(1MB) of your org. (See:http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation.htm#IsTest_topic).
Write your test methods in a separate test class.Remember the test class should be started with "@isTest " notation.
Creating an object of your class in your test class will not cover your test requirement, but doing so sometimes you may be able to cover the codes in the constructor of your class. But remember it doesn't do what we expect from a test class. First you have to create an object of your class in the test class and then you should try to call all the methods in your class, inside the test class by using the object reference you created. Then you should check whether the expected result would come.
See following example...
If your class is 'MyClass' and your test class is 'TestMyClass' and 'MyClass' has a method named 'getText()' which returns the string 'My text', then your test class should be something as follows.

@isTest
private class TestMyClass{ //test class start

static testMethod void myTest(){ //test method start

MyClass myCls = new MyClass(); //Create object reference of 'MyClass'

String text = myCls.getText(); //run getText() method

System.assertEquals('My text',text ); //check whether expected result has received

} //test method ends
}



Message Edited by prageeth on 02-03-2009 12:36 AM