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
davidjbbdavidjbb 

Test Case

Hello,

 

What's a good way to write test cases for fields that you've created within a class.

 

i've created alot of fields that are used on a VF page..I've already used all the methods within the Test case, but Salesforce shows a red line on the bolded.

 

My test method is also used within the same class.

 

so..

public with sharing class UMaterialController 

{

private string test;

test = 'asdf';

etc..etc..

 

public string getTest()
{
return test;
}

 

 

static testMethod void UMaterialControllerTest(){

 

}

}

 

 

ShamilShamil

If you have specific logic that assigns values to your fields, you should call that logic in the test class and then assert that the values assigned to the fields are correct.

If there's no specific logic and you'd simply like to cover your fields-related code, call a setter method to set a value, then call the getter and assert that the value has been assigned. In your case:

 

controller.setTest('someValue');

System.assertEquals(controller.getTest(), 'someValue');

 

One more thing: don't use browser to run your unit tests, use the Force.com IDE instead. The browser doesn't correctly display the covered lines.

davidjbbdavidjbb
woDetails = [Select CaseNumber, Account.Name, Contact.Name, Account.ShippingCity,
 	   Account.ShippingStreet, Account.ShippingState, Account.ShippingPostalCode,
 	   Account.ShippingCountry, start_date__c, finished_date__c from Case where id=:idCase];
 
 	  
 	   for(Case wo: woDetails){
 	   woNumber = wo.CaseNumber; // Order No
 	   accName = quotes+ wo.Account.Name +quotes; //Account Name
 	   //contactName =quotes+ wo.Contact.Name + quotes; //Contact Name of the Job Site
 	   city = quotes+ wo.Account.ShippingCity+quotes; //City of the Job Site
	   street = quotes+ wo.Account.ShippingStreet+ quotes; //Street of the Job Site
 	   state = quotes+ wo.Account.ShippingState+ quotes; //State of the Job Site
 	   postalCode = quotes + wo.Account.ShippingPostalCode + quotes; //Postal Code of the Job Site
           country = quotes + wo.Account.ShippingCountry + quotes; //Country of the Job Site
 	   entryDate = quotes + wo.start_date__c.month()+ '-' + wo.start_date__c.day()+ '-' + wo.start_date__c.year() +quotes; //There's formatting issue//
 	   endDate = entryDate;
 	   }

How would you do something like this.