A unit test is code that is written and executed to test a specific portion/unit of source code. Unit tests are class methods with the testMethod modifier or @isTest annotation and are usually placed in separate test classes annotated with the @isTest annotation. Code that is executed by unit ...

learn more… | top users | synonyms (2)

0
votes
0answers
23 views

I need test class for this? [on hold]

public class sendEmail5{ public quote getQ() { return q; } public sendEmail5(ApexPages.StandardController controller) {} public String emailVal{get;set;} public String ...
11
votes
1answer
58 views

Is it possible to simulate record locks in test methods?

I would like my test cases to also test exception handling. In theory an easy way to cause an exception on DML is to lock a record that it'll update so that the update will fail. But I'm having ...
4
votes
2answers
60 views

System.QueryException: No Such Column - Strange RunAs Behavior with Summer '14?

Question Is there any known reason a SOQL Query would return a runtime System.QueryException on a custom field in test methods, in particular one one via a parent lookup in a test? I would have ...
1
vote
3answers
48 views

Is it possible to get 100% Apex code coverage all the time?

Is it possible to get 100% code coverage all the time by considering all cases such as positive/negative, bulk/single etc. Are there any cases which can't be covered by test classes? I often hear that ...
0
votes
0answers
19 views

Suggested Unit Testing Approach When Checking for XML Child Nodes

Unit testing is currently at 60% code coverage on a specific class. Many of the lines of code that aren't covered by tests look like the following: global class IFXIndividuals { global ...
5
votes
5answers
280 views

Why isn't a SOQL query of mine populating a list in an Apex test class?

Why does my taskOpp query below not return any records when I run this test? The query works fine in Workbench and my taskRT query works fine in both my code and in Workbench. public class ...
1
vote
1answer
29 views

Advice on writing basic Apex Unit Test

The purpose of the controller below is to return the value of the one__c field on the Acc_Plan__c object, and then pass it into the getIsOneTrue() method. The controller works fine, but I have to ...
1
vote
0answers
27 views

Calling a webservice method from apex test class

I have a simple webservice method that updates Account Status from a custom Button in the Opportunity page: Global class Backoffice { WebService static Integer GenerateBackofficeTask(id opId) { ...
-1
votes
0answers
21 views

Test class doesn't cover Trigger [duplicate]

Can anyone give me the test code for my apex trigger: trigger Test_Share on Test__c (after insert) { Id UserId=UserInfo.getUserId(); Boolean bln=false; List<Id> ParentUserId = new ...
0
votes
1answer
23 views

Inserting Test.loadData in into Salesforce DB for tests

I am able to load the static resource but I am unable to insert the loaded accounts into salesforce. I want to do this to be able to test various methods that depend on first selecting a particular ...
0
votes
1answer
31 views

Invalid Cross Reference Key : Record Type ID value isn't valid for User: 012v00000008f4nuBB

I am having some issues. The below is a code snipet of my test class. The class complies and produces 96% of coverage with no errors. When deploying in production it throws the above error. ...
0
votes
0answers
22 views

Test class assertion failure and test coverage issue [closed]

I am getting below error message. while running test class. System.AssertException: Assertion Failed Class.CommunityNewsTest.SnapshotTest: line 35. **this is line 35 ** ...
0
votes
0answers
17 views

test class and coverage issue [closed]

Test class and coverage issue . Getting only 50 %. .... @isTest public class CommunityNewsTest { public static testMethod void testTableRecords(){ for(Integer i=0;i<10;i++){ ...
3
votes
1answer
28 views

System.VisualforceException: Invalid value for property label: null

Sigh. So I am required to cover my Apex code with tests. I'm testing a piece of code that dynamically builds a tree of controls with a PageBlock as the root object. This code works fine when NOT ...
2
votes
1answer
21 views

Speedup Testing with Force.com IDE using slim Logs - but how to set the log-level?

A lot has been written here about slow development in general and slow testing in particular e. g.: Slow development Faster unit tests? For my use case I found one reason for slow testing while ...
-1
votes
1answer
31 views

Apex Testing - Best Practices [closed]

A general question asked from time to time on stack exchange is how to implement tests. There are some general questions to ask: What are your testing best practices? Thanks for sharing your ...
1
vote
1answer
14 views

Production Test Execution “Could not run tests on class …”

While running my test cases within my prod environment, I noticed quite a few messages as the title describes, and I don't understand why. Do you have any insight on why this is happening? It seems to ...
1
vote
1answer
99 views

Can some help me get coverage for the below trigger?

Trigger: Trigger copyEquipmentonsite on Unit_Placements_Sales__c(after insert, after update) { List<Services__c> sub=new List<Services__c>(); for(Unit_Placements_Sales__c u : ...
1
vote
1answer
47 views

Unit Tests max number of test methods in a class?

I have many unit test methods (30+) in a test class that cover my class well - setting up data, setting the page and controller, calling methods and setting properties, doing asserts. But when I look ...
1
vote
1answer
32 views

Test for sendEmail() error

Hi I have built a class and a test and I am getting close to getting the test to work. I am trying to send an email using a template. But I am getting an error on the last line of code. Save ...
0
votes
2answers
40 views

How to call action function method in the test class

How do I call a method in my test class which is basically been called from the action function on the vf page? VF page: <button type="button" onclick="myJSMethod();">my button</button> ...
0
votes
1answer
20 views

Performing an Upsert in PageReferenceSave - Not updating Item.ID for Use In UnitTest

I have a test that creates a new record in our custom table - Service Offered. Whe I call my controller and save - It creates/updates the record correctly, and in my class the Debug.Assert gives me ...
3
votes
1answer
59 views

How to mock a SOQL query in Apex

Our Apex unit (true integration) test run takes about an hour to complete (260+ individual unit tests) and this really slows down our dev process as we are trying to adhere to Continuous ...
0
votes
0answers
42 views

Insert contact statement in test class is causing 0% code coverage

I've written a simple trigger to prevent duplication of a lead based on existing leads and contacts. My test has 90% code coverage based on the tests that I've written to prevent lead duplication. ...
1
vote
1answer
42 views

How to access recordType in Test Methods with seeAllData = false

I am writting a test method for a certain code.This code is fetching Record Type detail from an Object Service_Form__c. Class: String recordTypeName; Schema.DescribeSObjectResult srfDescribe = ...
0
votes
1answer
29 views

How do I write a test class for the below trigger? [closed]

I have just created the below trigger that is deigned to create a new custom object record(Services) when a custom date field (Service_Date__c) on another custom object (Unit)is equal to "This Month". ...
3
votes
0answers
67 views

Unit Test: You have uncommitted work pending. Please commit or rollback before calling out

So I have a method that takes as a parameter an Id of a object and uses it to make an external callout. Unfortunately I can't seem to figure out any way to test it. @isTest static void ...
2
votes
2answers
29 views

Testing code where maintenance tables are involved

I suppose this is more of a general programming question than a strictly Salesforce question. I have a trigger which clones / creates new record when criteria fits the match: trigger cloneObj on ...
4
votes
2answers
95 views

Scheduling Run All Tests

is there a simple way to schedule the run of all test classes? I want to avoid having to do this manually every day. Thank you!
2
votes
1answer
30 views

Test Class is not working for Map in class

I am not able to get coverage for the Maps in the class. I only getting 54% coverage and don't know what else to try. Can anyone please help me here. I will truly appreciate it! public with sharing ...
0
votes
2answers
31 views

Inserting test data using a list or a map to reduce the number of DMLs and get different Ids for different tests

Refer to below test class, @isTest public with sharing class CategoryHelperTest { private static boolean testDataCreated = false; private static Scheme__c ss; private static ...
0
votes
2answers
64 views

Apex Test Class - After Update Trigger

I have a test class that is only covering my trigger 48% and I want to get it as close to 100% as possible. It appears there is one section that I am not covering when using the Developer Console but ...
0
votes
2answers
49 views

Problem in System.assertEquals method [closed]

I am writing test class in which I'm inserting 5 custom objects. My question is that do i need to add System.asertEquals for each and every object or to add to any one is sufficient.
0
votes
2answers
19 views

Inserting test data using a list to reduce the number of DMLs

I got the below test class, @isTest public with sharing class CategoryHelperTest { private static boolean testDataCreated = false; private static Scheme__c ss; private static ...
2
votes
1answer
217 views

How to write test coverage for private method in controller?

How can I test private methods in an apex controller ? For instance this example: private static string getUserId(String str){ string UserId = ''; if(ref != null){ ...
0
votes
1answer
27 views

Does anyone recognize this error message pop up in Salesforce?

I'm trying to run some tests in the Salesforce 'Apex Test Execution' page and suddenly this error message has popped up, it keeps appearing when I press the 'Select Tests...' button. Has anyone seen ...
1
vote
1answer
89 views

System.NullPointerException: Argument cannot be null

Im getting the error 'System.NullPointerException: Argument cannot be null' when I run my test class, in the below test method. /* * update a existing report */ static testMethod void ...
0
votes
1answer
39 views

test class is not covering email messaging

trigger: trigger TaskCompletion on Task (after insert,after update){ IF(trigger.isinsert){ for (Task E : Trigger.new){ If((E.CreatedById != ...
0
votes
0answers
40 views

Help regarding test case code coverage

public with sharing class searchpn { //variables Public Id parentId; public Integer qliRowNum1{get;set;} public Integer qliRowNum{get;set;} public Integer finalRowNum{get;set;} ...
1
vote
3answers
104 views

0% code coverage Test APEX class

I have set up a simple APEX class that is an extension for a Visualforce page. The VF page has a commandButton that saves and takes you to a different page called "Congratulations.vfp" I have been ...
1
vote
1answer
43 views

APEX Unit tests hello world

I am trying to learn how to do APEX testing but all the tests in the documentation are too complex and I can't find an example of a simple APEX Controller that is a Hello World Test. I have this APEX ...
2
votes
1answer
43 views

How to use Pattern matching in test class for email field?

I am using pattern matchers for the email filed in contact in my development. When writting the test i am getting error in that patter matches.Here i have method the error line.Kindly help me to ...
-2
votes
1answer
54 views

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING in test class

Class: public class CreatePurchaseorder{ public Purchase_order_setting__c pos {get;set;} public boolean isInput{get;set;} public id poid{get;set;} public boolean isUpdt{get;set;} ...
4
votes
0answers
63 views

Creating Idea Votes from portal user in Test code. DML Exception

I Wrote a very simple VF Page and Controller to show the Accounts that voted on certain Ideas. Here is the controller. Just aggregates the Up and Down votes on the Idea excluding internal votes. ...
0
votes
2answers
33 views

VF Controller Test Class

I have been trying to create a test class for my controller for my visual force page and I am not grasping the concepts behind it, can someone help me get started? I have tried a few things but I have ...
2
votes
1answer
54 views

I have this trigger and test class . why my test class cover 0%

trigger openTrigger on Project_Item__c (after insert,after update,after delete,after undelete) { Project_Item__c[] items; //Use Trigger.old For After Delete and The Others is Trigger.new ...
0
votes
0answers
64 views

Incorrect code coverage in developer console

I have an apex class called RelationshipTreeController (RTC for short) and a test class called RelationshipTreeControllerTest (RTCT for short). I have written a test method that calls the search() ...
1
vote
1answer
34 views

Need help for custom controller test class

i implemented chatter check in for this blog: http://intmist.wordpress.com/2014/03/23/show-custom-visualforce-page-in-salesforce1-setup-publisher-action-and-check-in-using-salesforce1-app/ do some ...
0
votes
2answers
40 views

how to write a test for read only Page

I have a page emitting XML for outside users. All it does is create xml from the data. I have a problem writing a test to cover it. The page is just: <apex:page showHeader="false" ...
2
votes
1answer
56 views

Passing related objects in tests

I have the following visualforce page: <apex:page standardController="Whatever__c" extensions="WhateverExt" action="{!autoRun}"> <apex:form > <apex:outputField ...