Test Class Coverage for Apex Controller I need help in writing test class for following apex class. Could anyone please suggest how to create test data,test the following method defined in apex class with positive and negative scenarios and use of System.assertEquals() to make sure each scenario had the expected outcome. customAppName field is multiselect picklist on customObject public with Sharing class abcService{   @AuraEnabled    public static List&lt;customObject&gt; xyzMethod(){          UserAppInfo userAppInfo = [SELECT Id, AppDefinitionId FROM UserAppInfo WHERE UserId =        :UserInfo.getUserId() LIMIT 1];       AppDefinition appDefinition = [SELECT DurableId, Label FROM AppDefinition Where DurableId =        :userAppInfo.AppDefinitionId LIMIT 1];       String appName = appDefinition.Label;       System.debug('appName-------&gt;' + appName);       return [SELECT custom fields FROM customObject  WHERE customAppName includes (:appName)];           } }  When I started creating test data got fields not writeable issue for UserAppInfo and AppDefinition. Based on the comments mentioned in the post, I started with test class but not able to cover the scenarios. @isTest public class abcServiceTest{     @testSetup    public static void testSetup(){         }  @isTest static void testPositiveScenario(){ //Passing App name          User u = someClass.testUserCreate();     System.runAs(u){                           Test.startTest();                  customObject__c customObjectObj = new customObject__c(custom_Id__c = 'Id_01', custom_Name__c = 'Test Name AA', customAppName__c = 'Test App AA');         insert customObjectObj;         List&lt;customObject__c&gt; customList = [SELECT custom_Id__c, custom_Name__c, customAppName__c FROM customObject__c WHERE customAppName__c INCLUDES ('Test App AA')];         System.debug('customList----------&gt;' + customList);         System.assertEquals(1, customList.size());               Test.stopTest();     }    }  @isTest static void testNegativeScenario(){         User u = someClass.testUserCreate();     System.runAs(u){         Test.startTest();                  customObject__c customObjectObj = new customObject__c(custom_Id__c = 'Id_02', custom_Name__c = 'Test Name BB', customAppName__c = 'Test App BB');         insert customObjectObj;         List&lt;customObject__c&gt; customList = [SELECT custom_Id__c, custom_Name__c, customAppName__c FROM customObject__c WHERE customAppName__c INCLUDES ('Test App CC')];         System.debug('customList----------&gt;' + customList);         System.assertEquals(0, customList.size());                  Test.stopTest();     }    }     }  Could anyone suggest how to have xyzMethod() covered. Any kind of help is appreciated.
How do I write an Apex unit test? This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, including more unit test resources, navigate to the  tag.  This canonical question is intended to address several classes of common questions by providing a quick summary and links to comprehensive resources:   How do I start writing my first unit test?  How do I unit test this code?  I need help writing this unit test.   Salesforce Stack Exchange looks for detailed, specific questions that the community can help you with, and can't write tests on your behalf. We feel that working with the resources below can help you get started, and we encourage you to make an attempt to write your test and return to SFSE with your specific questions when you encounter challenges you can't resolve.
Is there a reason the British omit the article when they "go to hospital"? Why do British speakers omit the article in constructions like "go to hospital" or "go on holiday"? Pretty much all American speakers would rephrase those as "go to the hospital" and "go on a holiday", I think. Is there any good reason, or forgotten sense behind those words that might explain why the articles are ommitted?  Are there other common constructions other than those two that the British use that drop the article?  EDIT: I just realized per Kosmonaut's comment that Americans do much the same thing with a few nouns, so this isn't all that special.   Do grammaticists designate nouns that can have their article dropped with anything, i.e. do they have anything in common? Edited photos have reverted to originals on iphone Types of things vs. types of thing I have several files that I ftp each hour.  The receiving system needs to have some sort of identifier that they came from the same batch, so I would like to append a timestamp to the filename.  That alone is fairly easy, but since I want each file to have the same timestamp (so it can serve as the batch identifier), I cannot figure out how to do this.  So, I have:  file1.txt file2.txt file3.txt   And I want to have:  file1_20141110184303.txt file2_20141110184303.txt file3_20141110184303.txt   Any use of the date +%Y%m%d%H%M%S after the first use will obviously result in a different values in seconds, so I would like to have the first timestamp appended to the remaining files. I just installed a new version of Ubuntu and I want to roll it back to the previous version.  How can I do that? Is that even possible? In Adobe Photoshop I am able to select multiple layers at once with Shift+Click.  How can I do that in GIMP? Travelling as unmarried couple in Dubai line segment joining two centers of circles is perpendicular to line segment joining two intersection point of the circles Why use the 'ref' keyword when passing an object? If I am passing an object to a method, why should I use the ref keyword? Isn't this the default behaviour anyway?  For example:  class Program {     static void Main(string[] args)     {         TestRef t = new TestRef();         t.Something = "Foo";          DoSomething(t);         Console.WriteLine(t.Something);     }      static public void DoSomething(TestRef t)     {         t.Something = "Bar";     } }   public class TestRef {     public string Something { get; set; } }   The output is "Bar" which means that the object was passed as a reference. How to deserialize a JSON String to Apex How do I change the default settings of export operators? Good and easy way to share files on local machine I would like to have a directory that has following properties:    Many users can copy files into it  These files can be deleted/changed by these users (user A can delete/modify file that was copied into this directory)    it cant be done using normal file permissions (because permissions are retained on copy).  Here is what I found on the net:        Some use cases:    Sharing music on local machine  Simple git repository sharing (just make a bare repository writeable to many people) --- i know that there are solutions like gitosis Allow many developers to modify test instance of php app without giving them root (i guess they would copy files) --- I'm leading a team of nonprofit junior developers and I need to keep that one simple!    EDIT  AFAIK setting SGID bit is not enugh, it only affects newly created files --- and basic workflow for these use cases ivnolves copying and other operations (which cleave file's gid unchanged) Geodesics equations via variational principle I would like to recover the (timelike) geodesics equations via the variational principle of the following action:  $$ \mathcal{S}[x] = -m \int d\tau = -m \int \sqrt{-g_{\mu\nu}\,dx^{\mu}\,dx^{\nu}} $$  Using an arbitrary auxiliary parameter $\lambda$, then one is able to rewrite the action and obtains: $$ d\tau = \sqrt{-g_{\mu\nu}\, \tfrac{dx^{\mu}}{d\lambda}\tfrac{dx^{\mu}}{d\lambda}} d\lambda $$ $$ -m \int d\tau = -m \int (d\tau / d\lambda) d\lambda =  -m\int\sqrt{-g_{\mu\nu}\, \tfrac{dx^{\mu}}{d\lambda}\tfrac{dx^{\mu}}{d\lambda}} d\lambda $$  Now we can vary the paths $x^{\mu}(\tau) \rightarrow x^{\mu}(\tau) + \delta x^{\mu}(\tau)$.  I need the following equation to be true, so i get the geodesics equations, but I don't know how one can say the following: $$ \int d\tau \,\delta g_{\mu\nu}\frac{dx^{\mu}}{d\tau} \frac{dx^{\nu}}{d\tau} = \int d\tau\, g_{\mu\nu, \rho} \frac{dx^{\mu}}{d\tau} \frac{dx^{\nu}}{d\tau} \delta x^{\rho} $$ I know there is a simpler action, which leads to the same equation of motion, but there one has to do the same manipulation, which I sadly don't understand.  Thanks for helping me! I'm attempting to modify the Table of Contents in my document. Currently, chapter one in my document is listed as   1   Introduction   What I would like to see is  Chapter 1   Introduction   Seems like an easy enough thing to ask for, but can't seem to find a good way to do this. Any feedback would be most appreciative. Is there a name for this database schema of key values? What characters are allowed for the display name? I tried editing my display name and for some names it gives me this error:     Display Name can only contain a-z, 0-9, spaces, apostrophes or hyphens and must start with a letter or number   That is clearly not the case, because it will take the following names:   NullUserException -龍- NullUserException Ω    NullUserException ఠ_ఠ NullUserException ಠ_ಠ NullUserException இ_இ   But it won't let me do:   NullUserException  (╯°o°)╯ NullUserException ٩๏̯͡๏)۶ NullUserException ☜(ﾟヮﾟ☜) NullUserException อ้_อ้   So what's the regex used (assuming that's what's being used), so I can try out allowed names without actually changing it? How to delete file(s) in secure manner? Is there a way to make sure that a deleted file can not be recovered?   As you know, deleting a file by pressing shift-del or using trash doesn't mean that file is gone forever. It resides somewhere in the computer.  In day to day life, law enforcement or thieves use recovery programs to reveal our private data or something else.   They can recover all data that resides on hard disk, in RAM, and even USB.  To protect us from these people, what should one do? Which program should one use?  Note: I don't want an answer like first use a recovery program then erase that file with shred. With just one program, I want to erase all unused/deleted files on my computer. How do you get a submit button in the Windows Phone keyboard? SSH: How to disable weak ciphers? Security team of my organization told us to disable weak ciphers due to they issue weak keys.    arcfour   arcfour128   arcfour256   But I tried looking for these ciphers in ssh_config and sshd_config file but found them commented.   grep arcfour * ssh_config:#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc   Where else I should check to disable these ciphers from SSH? Create WiFi hotspot on ubuntu