You need to sign in to do that
Don't have an account?
MaddyConnect
Test coverage for class properties using test class
Hi,
I have below class defination and it has no method:
public class ExampleClass
{
public String name {get; set;}
public String Week_Ending{get; set;}
public String Depot {get; set;}
public String Type_Of_Work{get; set;}
}
I tried various ways to cover this class with no luck. Please help to resolve test class to cover such type of class.
Thanks,
Maddy
I have below class defination and it has no method:
public class ExampleClass
{
public String name {get; set;}
public String Week_Ending{get; set;}
public String Depot {get; set;}
public String Type_Of_Work{get; set;}
}
I tried various ways to cover this class with no luck. Please help to resolve test class to cover such type of class.
Thanks,
Maddy
Use Below Code
Test Class:
Let us know if it helps you.
All Answers
Just create an instance of this class like below line. it will automatically be covered then.
Let us know if it helps you.
Just initializing your apex class in test method is sufficient for your problem,
Please go through the below link for how to write test class,
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Please mark this as a solution if you satisfied..!
I already tried creating instance of class to be tested in test class. Its not covering single line. Thanks for your replies.
Thanks,
Maddy
Please paste your test class here.
You just create a constructor and initalize all your variables..Because as a best practsie we should always initalize all are varaiables..
like
Then you cna simply create instance of this class it will cover..make sure you are createing instance in test class then only it will cover...not in normal apex class...
your test class will have test method where you will cerate instance
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
public class textData
{
public String name {get; set;}
public String Week_Ending{get; set;}
public String Project_Ref{get; set;}
public String Project_Ref_Name{get; set;}
public String Depot{get; set;}
public String Type_Of_Work{get; set;}
public String Lay_Material{get; set;}
public String Material_Type{get; set;}
public String Diameter_Laid{get; set;}
public String Abandon_Main_Length{get; set;}
public String Abandon_Main_Size_Imperial{get; set;}
public String Abandon_Main_Size_metric{get; set;}
public String DIV_LT180mm{get; set;}
public String DIV_GT250mm{get; set;}
public String Reinf_LT180mm{get; set;}
public String Reinf_GT250mm{get; set;}
public String Repl_LT180mm_INS{get; set;}
public String Repl_LT180mm_Mole{get; set;}
public String Repl_LT180_O_C{get; set;}
public String Repl_GT180_LT355_Mole{get; set;}
public String Repl_GT180_LT355INS{get; set;}
public String Repl_GT180_LT355O_C{get; set;}
public String Repl_GT355mm_INS{get; set;}
public String Repl_GT355mm_Mole{get; set;}
public String Repl_GT355mm_O_C{get; set;}
public String Services_Non_Dom{get; set;}
public String Services_Relay_INS{get; set;}
public String Services_Relay_Mole{get; set;}
public String Services_Relay_O_C{get; set;}
public String Services_Transfer{get; set;}
public String Team{get; set;}
}
Test Class:
@isTest
private class textDataTest
{
static testMethod void myUnitTest()
{
textData t = new textData();
//Tried by assigning values as below
/*t.Depot = 'test';
t.Abandon_Main_Length = 'test';
t.Abandon_Main_Size_Imperial = 'test';
t.Abandon_Main_Size_metric = 'test';
t.Diameter_Laid = 'test';
t.DIV_GT250mm = 'test';
t.DIV_LT180mm = 'test'; */
}
}
Please change your class code with below then try to write test class
I think it will solve your problem .
Use Below Code
Test Class:
Let us know if it helps you.
@isTest
private class textDataTest
{
static testMethod void myUnitTest()
{
textData t = new textData();
t.Depot = 'test';
t.Abandon_Main_Length = 'test';
t.Abandon_Main_Size_Imperial = 'test';
//Assign values to all memebers of class
}
}
apex class:
public class JiraDataCommon {
public class JiraUser{
public String name;
public String emailAddress;
public String accountId;
public String displayName;
}
public class JiraSearchRequest{
public List<String> expand;
public String jql;
public Integer maxResults;
public Boolean fieldsByKeys;
public List<String> fields;
public Integer startAt;
}
public class JiraNotificationRequest{
public String htmlBody;
public String subject;
public String textBody;
public Map<String,Object> to;
}
}
Apex test class:
@isTest
public class JiraDataCommon_Test{
static testMethod void test_JiraUser (){
JiraDataCommon.JiraUser obj11 = new JiraDataCommon.JiraUser();
obj11.name = 'test1';
obj11.emailAddress = 'sfadmin@demandblue.com';
obj11.accountId = '01p2v00000INJ32';
obj11.displayName = 'test data';
}
static testMethod void test_JiraSearchRequest(){
JiraDataCommon.JiraSearchRequest obj61 = new JiraDataCommon.JiraSearchRequest();
obj61.expand = new List<String>();
obj61.jql = 'test data';
obj61.maxResults = 10;
obj61.fieldsByKeys = false;
obj61.fields = new List<String>();
obj61.startAt = 10;
}
static testMethod void test_JiraNotificationRequest(){
JiraDataCommon.JiraNotificationRequest obj131 = new JiraDataCommon.JiraNotificationRequest();
obj131.htmlBody = 'htmlbody';
obj131.subject = 'subject';
obj131.textBody = 'textbody';
obj131.to = new Map<String,Object>();
}
}