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
BrianWKBrianWK 

Test Class passes when run on it's own, but fails when run with all test classes

Hey everyone.

 

I'm scratching my head on this one. I have a test class with a system asserts. Everything evaluates correctly if I open that Test Class and click "Run Tests."

 

However, when I go to the Apex Classes page and click "Run Tests" across all my test classes -- the system assert fails.

 

I'm having a hard time tracking this down. My expectation would be that the test class would return consistent results. Anyone have any thoughts of where I can begin to look?

tmatthiesentmatthiesen

Can you provide further detail to repro this?  testmethod executions should act like siloed events with zero impact on other test executions.

BrianWKBrianWK

Tmatthiesen --

 

Part of my problem is I'm not sure what's happening so it's tough to reproduce. To make it worse, the last few test didn't return the same issue. So sometimes it happens, sometimes it doesn't.

 

Basically the test method in question creates a series of Accounts. It then takes those Accounts and pushes it into the Class Method I'm testing. The result is that the Accounts should have a field populated with an ID of a different Account. Basically I'm short circuiting the ParentID hierarchy so the field points to the Account at the very top of the Hierarchy list.

 

My system assert basically says Account1.Top_Hierarchy == Top_Hierarchy.id. What's happening is this assert fails because the Account1.Top_Hierarchy == null; This doesn't make sense since it could only happen if the Query is wrong. The functional test provides the correct functionality. If I call the functionality by anon execute it works perfectly.

 

It's only this test method where it causes problems when I run it with all test classes -- and only that assert statement.

 

The only thing I can think of is that there was a versioning error. I did re-deploy all my code to our QA sandbox. I've gotten the error once since then, but haven't been able to reproduce it after. So I'm not very confused!

tmatthiesentmatthiesen

Let me know if/ when you can repro and I'll see if our QA team can investigate.

BrianWKBrianWK

Thanks tmatthiesen.

 

If I can get the code to consistently do it again, I'll let you know. I haven't a clue what would be causing the issues so it's tough to purposefully try to reproduce it.