You need to sign in to do that
Don't have an account?
SalesforceUser11
How to increase test coverage
Hi,
My test class is passed but test coverage is 0%. Can any one help to increase tets coverage:
APex Class:
public class TopicOfInterestUserAsgmtDataAccessor implements TopicOfInterestUserAssignmentDAI {
public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestByUserId(Id userId) {
return [
SELECT Id,
User__c,
TopicofInterest__c
FROM Topic_of_Interest_User_Assignment__c
WHERE User__c = :userId];
}
public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestLabelsByUserId(Id userId) {
return [
SELECT Id,
User__c,
toLabel(TopicofInterest__c)
FROM Topic_of_Interest_User_Assignment__c
WHERE User__c = :userId];
}
public void upsertUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> newOrExistingTopics) {
upsert newOrExistingTopics;
}
public void deleteUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> existingTopics) {
delete existingTopics;
}
}
Test Class:
@IsTest
private class TopicOfInterestUserAsgmtDataAccessorTest {
@testSetup
private static void testSetup() {
}
@isTest
Private static void testgetSubscribedTopicsOfInterestByUserId() {
Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
User u = new User(Alias = 'standt', Email = 'standarduser@testorg.com',
EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US', ProfileId = p.Id,
TimeZoneSidKey = 'America/New_York', UserName = 'standarduser1@testorg.com');
System.runAs(u) {
Topic_of_Interest_User_Assignment__c tci = new Topic_of_Interest_User_Assignment__c();
tci.User__c = u.Id;
tci.TopicofInterest__c = 'Administrative';
insert tci;
system.debug('**************tci'+tci);
}
}
}
My test class is passed but test coverage is 0%. Can any one help to increase tets coverage:
APex Class:
public class TopicOfInterestUserAsgmtDataAccessor implements TopicOfInterestUserAssignmentDAI {
public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestByUserId(Id userId) {
return [
SELECT Id,
User__c,
TopicofInterest__c
FROM Topic_of_Interest_User_Assignment__c
WHERE User__c = :userId];
}
public List<Topic_of_Interest_User_Assignment__c> getSubscribedTopicsOfInterestLabelsByUserId(Id userId) {
return [
SELECT Id,
User__c,
toLabel(TopicofInterest__c)
FROM Topic_of_Interest_User_Assignment__c
WHERE User__c = :userId];
}
public void upsertUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> newOrExistingTopics) {
upsert newOrExistingTopics;
}
public void deleteUserTopicSelections(List<Topic_of_Interest_User_Assignment__c> existingTopics) {
delete existingTopics;
}
}
Test Class:
@IsTest
private class TopicOfInterestUserAsgmtDataAccessorTest {
@testSetup
private static void testSetup() {
}
@isTest
Private static void testgetSubscribedTopicsOfInterestByUserId() {
Profile p = [SELECT Id FROM Profile WHERE Name = 'System Administrator'];
User u = new User(Alias = 'standt', Email = 'standarduser@testorg.com',
EmailEncodingKey = 'UTF-8', LastName = 'Testing', LanguageLocaleKey = 'en_US',
LocaleSidKey = 'en_US', ProfileId = p.Id,
TimeZoneSidKey = 'America/New_York', UserName = 'standarduser1@testorg.com');
System.runAs(u) {
Topic_of_Interest_User_Assignment__c tci = new Topic_of_Interest_User_Assignment__c();
tci.User__c = u.Id;
tci.TopicofInterest__c = 'Administrative';
insert tci;
system.debug('**************tci'+tci);
}
}
}
Below class should give you 100% coverage. Dont forget to add appropriate assert statments.
Please mark this as the best answer if this resolves your issue. Thanks.
All Answers
Below class should give you 100% coverage. Dont forget to add appropriate assert statments.
Please mark this as the best answer if this resolves your issue. Thanks.
Thanks! Code covered by 100%. Really thanks for help.