You need to sign in to do that
Don't have an account?

How to write code coverage for this controller
public with sharing class pdfViewController {
public Document doc{
get {
if (doc== null) {
doc= [SELECT id,Body, ContentType FROM Document WHERE ID ='0159E0000009NGe'];
}
return doc;
}
private set;
}
public String pdf {
get {
return EncodingUtil.Base64Encode(doc.body);
}
}
}
public Document doc{
get {
if (doc== null) {
doc= [SELECT id,Body, ContentType FROM Document WHERE ID ='0159E0000009NGe'];
}
return doc;
}
private set;
}
public String pdf {
get {
return EncodingUtil.Base64Encode(doc.body);
}
}
}
If you need to access the existing data from Test class, you have to use the annotation (seeAllData=true).
@isTest(seeAllData=true)
public class Test_PdfViewCtrl{
static testMethod void test_PDF(){
pdfViewController pd = new pdfViewController();
Test.StartTest();
Document doc = pd.doc;
String pdf = pd.pdf;
system.assertEquals('bssds', pdf);
Test.StopTest();
}
}
The above code will provide you 100% coverage.
Regards
Harini
All Answers
Public Class Test_PdfViewCtrl{
static testMethod void test_PDF(){
pdfViewController pd = new pdfViewController();
document doc = [SELECT id,Body, ContentType FROM Document limit 1];
string pdf = EncodingUtil.Base64Encode(doc.body);
system.assertEquals('bssds', pdf);
}
}
it shows 0 % coverage.
If you need to access the existing data from Test class, you have to use the annotation (seeAllData=true).
@isTest(seeAllData=true)
public class Test_PdfViewCtrl{
static testMethod void test_PDF(){
pdfViewController pd = new pdfViewController();
Test.StartTest();
Document doc = pd.doc;
String pdf = pd.pdf;
system.assertEquals('bssds', pdf);
Test.StopTest();
}
}
The above code will provide you 100% coverage.
Regards
Harini
First insert document record and then call it in test class like below.
plz check once and let me know.
Thanks
Varaprasad