You need to sign in to do that
Don't have an account?
arosys
75% test coverage is required
I am stuck at this can anyone help me out in this.
This is my visualforce page
public class WebserviceAccountExtensionNew{ public String[] result{get; private set;} public Map<String,String> accountMap{get;set;} public string AccountName{get;set;} public string OutPutString{get;set;} public string OrganisationId{get;set;} public string UserId{get;set;} public string type{get;set;} public string DMpwd{get;set;} public string DMSecureKey{get;set;} public boolean toperrmsg{get;set;} List<Datamapia__Datamapia_User__c> user; public PageReference CallWebservice() { if(AccountName == null || AccountName == '') { System.debug('.......') ; ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Account Name cannot be null'); ApexPages.addMessage(myMsg); /* if(!accountMap.isEmpty()) { accountMap.clear(); }*/ } else { accountMap = new Map<String, String>(); OrganisationId = UserInfo.getOrganizationId(); UserId = UserInfo.getUserId(); type= 'accounts'; user=[SELECT Datamapia__DMSecureKey__c,Datamapia__Password__c FROM Datamapia__Datamapia_User__c]; for(Datamapia__Datamapia_User__c u : user) { DMpwd = u.Datamapia__Password__c; DMSecureKey = u.Datamapia__DMSecureKey__c; } accountMap.clear(); searchnewDatamapiaCom.AccountsWSPort stub = new searchnewDatamapiaCom.AccountsWSPort(); stub.timeout_x = 120000; result= stub.GetSuggestions(AccountName,type,OrganisationId,UserId,DMSecureKey,DMpwd); if(result != null ){ for (Integer i=0; i < result.size(); i++) { String[] part = result[i].split('\\|'); if(part.size() == 1) { OutPutString ='Invalid request !'; accountMap.clear(); } else { accountMap.put(part[0].substring(0,15), part[1]); OutPutString = 'Please reivew the account names below. If you still wish to continue , click Create New!' ; } } } else { OutPutString ='No matches found !'; accountMap.clear(); } } return null; } public PageReference doCancel() { return null; } }
This is my apex class :
public with sharing class WebserviceAccountExtension{ private final Account acct; public String[] result{get; private set;} public Map<String,String> accountMap{get;set;} public string AccountName{get;set;} public string OutPutString{get;set;} public string OrganisationId{get;set;} public string UserId{get;set;} public string type{get;set;} public string DMpwd{get;set;} public string DMSecureKey{get;set;} ApexPages.standardController m_sc = null; List<Datamapia__Datamapia_User__c> user; public WebserviceAccountExtension(ApexPages.StandardController stdController) { this.acct = (Account)stdController.getRecord(); m_sc = stdController; } public PageReference CallWebservice() { if(AccountName == null || AccountName == '') { System.debug('.......') ; ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Account Name cannot be null'); ApexPages.addMessage(myMsg); } else { accountMap = new Map<String, String>(); OrganisationId = UserInfo.getOrganizationId(); UserId = UserInfo.getUserId(); type= 'accounts'; user=[SELECT Datamapia__DMSecureKey__c,Datamapia__Password__c FROM Datamapia__Datamapia_User__c]; for(Datamapia__Datamapia_User__c u : user) { DMpwd = u.Datamapia__Password__c; DMSecureKey = u.Datamapia__DMSecureKey__c; } accountMap.clear(); searchnewDatamapiaCom.AccountsWSPort stub = new searchnewDatamapiaCom.AccountsWSPort(); stub.timeout_x = 120000; result= stub.GetSuggestions(AccountName,type,OrganisationId,UserId,DMSecureKey,DMpwd); if(result != null ){ for (Integer i=0; i < result.size(); i++) { String[] part = result[i].split('\\|'); if(part.size() == 1) { OutPutString ='Invalid request !'; accountMap.clear(); } else { accountMap.put(part[0].substring(0,15), part[1]); OutPutString = 'Please reivew the account names below. If you still wish to continue , click Create New!' ; } } } else { OutPutString ='No matches found !'; accountMap.clear(); } } return null; } public PageReference doCancel() { return m_sc.cancel(); } }
And this my test class :
@isTest public class thecontrollerTests { public static testMethod void testWebserviceAccountExtension() { String txt = 'test'; PageReference pageRef = Page.DatamapiaAccount; Test.setCurrentPage(pageRef); Account a = new Account(name='Tester'); insert a; ApexPages.StandardController sc = new ApexPages.standardController(a); Test.startTest(); WebserviceAccountExtension e = new WebserviceAccountExtension(sc); System.assert( e != null); e.AccountName= txt; System.assertEquals(txt,e.AccountName); List<Apexpages.Message> msgs = ApexPages.getMessages(); boolean b = false; for(Apexpages.Message msg:msgs){ System.assertEquals(ApexPages.Severity.ERROR, msg.getSeverity()); } String testCancel = e.doCancel().getUrl(); Test.stopTest(); } }
On uploading the package it says "Average test coverage across all Apex Classes and Triggers is 69%, at least 75% test coverage is required."
Thanks in advance.
Hi,
Check which part of your code is not covered from developer console and try to cover those test cases.
Thanks,
Maf