Questions tagged [test-setup]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
10
votes
3answers
929 views

Why do Methods marked @TestSetup in Classes marked @IsTest count against test coverage requirements?

Every test class on my org that has a TestSetup annotated method shows 0/n lines covered in the developer console (Where n is the number of lines in the annotated method). I thought maybe this was ...
12
votes
5answers
3k views

What are the advantage of the @testSetUp annotation

Before Salesforce introduced @testSetup annotation in 2015, I used to create common data in a method and call it in every test method. Ex: @isTest private class clsAccountTest { private static ...
19
votes
1answer
4k views

How do governing limits work with @testSetup from Spring 15' release

The new @testSetup method is covered pretty well by Jesse Altman in his: New Spring ’15 Feature: @testSetup article but as mentioned in the comments, there is a question about how this new feature ...
10
votes
1answer
930 views

How to create test data for a class that checks for historical data?

I have a class that processes some data returned by a query. The query is based on the createddate column of the object. In this case, the query specifically retrieves data created 3 days before today....
10
votes
1answer
287 views

Why does an autonumber sequence get “stuck” when creating records after a @testSetup method?

I ran into this while writing unit tests for my org but I simplified it in a developer account to make sure it would happen there. I have custom object Thing__c. The Name field is autonumber. I wrote ...
10
votes
1answer
531 views

Are @future methods ignored in @TestSetup blocks?

Ok, this is going to become a quite long question. The main goal is to document strange platform behavior and maybe learn more why this happens. It all started with that test which failed because ...
4
votes
1answer
1k views

Avoiding Governor limits on test classes

We have a custom application created on force.com platform which has a lot of unwanted SOQL Queries and DML Statements written in a poor format. We are trying to stabilize the code now and looking ...
8
votes
3answers
11k views

Retrieving records from @testSetup Method

I'd like to create records in @testSetup for my Test Class, to avoid the need to create the same records for each of the methods in the class. I also need to create both a User record and Custom ...
3
votes
1answer
738 views

How to share an object between test methods?

I get System.NullPointerException: Attempt to de-reference a null object when I try to do the following: @isTest private class MyControllerTest { static MyController controller; @testSetup ...
3
votes
2answers
182 views

How is it possible for @TestSetup to effect test result?

While refactoring a test to make it more consistent with the style of our other tests, a colleague came upon something really weird. The original test created the test account in @TestSetup, like so: ...
1
vote
1answer
849 views

Delete failed exception when creating test data in an @TestSetup method

I'm trying to create an @TestSetup method for my test class, but I'm getting an exception that makes no sense to me whatsoever and I have no idea how to get past it. Consider the code: @TestSetup ...
0
votes
1answer
129 views

Losing all test coverage when testing individual class

I am writing tests for my apex classes. Usually I can test each test class individually from the developer console. When I run the idividual test my code coverage is 0% even if the class passed. My ...