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
Jack Rose 1Jack Rose 1 

Unable to deploy without Apex Test


Really hoping someone is able to help me with an issue I'm having. I am a Salesforce Admin with no developer to hand. 
I am trying to do a change set to our Production Org, for a Apex Class. The purpose of the class is to insert the Data Categories into Custom Fields on the Knowledge Article. 
Unfortunately my change set failed as my test coverage was 0%. 

I have since discovered that I need a test class for the Apex Class but have no idea where to start. 
Here is the class I have, any help would be greatly appreciated. 
public class DataCategoryMgmtDL4B {
    public static void updateArticleTypeForDataCategories(List<Id> articleTypeIds)
        List<string> DL4B_Products = new List<String>{'Property_Owner_Residential','Property_Owner_Commercial','Tradesman','Retail','Business_From_Home','Office_and_Surgery','Hotel','Pub_Restaurant','Tradesman_Professional','Property_Owner','Bed_Breakfast','Hair_Beauty','Office_Professional','Professional_Indemnity','Cyber','Van'};
        List<string> DL4B_Systems = new List<String>{'Acturis_ETrade','Evo','IS2000','PI_Legacy','SSP','UIS'};
        List<Knowledge__kav> lstArticleType = [SELECT Id, Title, DL4B_Data_Categories__c, DL4B_Systems_Categories__c FROM Knowledge__kav WHERE Id IN:articleTypeIds
                                                    AND PublishStatus = 'draft'];
        List<Knowledge__DataCategorySelection> lstDC = [SELECT ParentId, DataCategoryName FROM Knowledge__DataCategorySelection
                                                            WHERE ParentId IN:articleTypeIds];
        Map<Id, String> datacategoryNameMap = new Map<Id, String>();
        for(Knowledge__DataCategorySelection dcObj:lstDC)
                String str =  datacategoryNameMap.get(dcObj.ParentId);
                datacategoryNameMap.put(dcObj.ParentId, str + ';' + dcObj.DataCategoryName);
                datacategoryNameMap.put(dcObj.ParentId, dcObj.DataCategoryName);
        for(Knowledge__kav artObj:lstArticleType)
                String allDataCategories = datacategoryNameMap.get(artObj.Id);
                List<String> parts = datacategoryNameMap.get(artObj.Id).split(';');
                artObj.DL4B_Data_Categories__c = '';
                artObj.DL4B_Systems_Categories__c = '';
                for(String unix: parts)
                        artObj.DL4B_Data_Categories__c += unix + ';';
                        artObj.DL4B_Systems_Categories__c += unix + ';';
        update lstArticleType;

Raj VakatiRaj Vakati
Try this test class
private class NewsComponentClassTest{
  static testMethod void MakeArticle() {
    User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
    System.runAs (thisUser) 
      Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
      User u = new User(Alias = 'standt', Email='', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id, 
        TimeZoneSidKey='America/Los_Angeles', UserName=''');

      insert u;

		// Test data and all required fields 
      Knowledge__kav newArticle = new Knowledge__kav
      (Title='test article', UrlName='testarticleurl', Language='en_US', DL4B_Data_Categories__c='Property_Owner_Commercial', DL4B_Systems_Categories__c ='IS2000'  

       // Insert Article
      insert newArticle;

      // Publish Article
      String articleId = newArticle.Id;
      KbManagement.PublishingService.publishArticle(articleId, true);