Skip to main content
9 events
when toggle format what by license comment
Sep 2 at 8:40 comment added Jazzer @DerekF Thanks for the clarification.
Aug 29 at 11:22 comment added Derek F @Jazzer @TestSetup isn't a separate transaction though, it just has the effect of wiping statics. If anything, it's closer to @BeforeAll in JUnit (with some odd behavior that still carries over limits usage to each individual test). Something that ostensibly only runs once for the entire test class. The entire run of a unit test class (with multiple test methods) appears to be a single transaction. The underlying test framework just does a more complete job of resetting the environment between individual tests.
Aug 29 at 10:54 comment added Jazzer @Moonpie as DerekF said, it's more of a code smell - if your test needs the code to run differently than it would in production, then it's not actually testing that it would work in production. You can look at what the difference is and reason that it will still work correctly in production but the test is not definitive proof of that. As with any rule, the skill of a developer is in knowing when it can/should be broken :)
Aug 29 at 10:49 comment added Jazzer @DerekF thanks for the detailed explanation, I hadn't realised that @TestSetup was a separate transaction (particularly given, as you say, that it's not a fresh set of limits) so that is at least a way forward. As for DI, we are indeed using injection to allow for proper unit tests, but I am also building a few integration tests which gave rise to this question.
Aug 29 at 10:44 vote accept Jazzer
Aug 28 at 17:29 comment added Derek F @Moonpie Not entirely sure myself. Maybe it's a bit "code smell"-y, probably not super elegant, mixes just a bit of "test" stuff into production code. Beyond that, it might mostly be OOP purity/dogma. I generally try to avoid it, but it is an easy way out (of mostly a design issue) when I do use it.
Aug 28 at 16:19 comment added Moonpie You state that "senior devs/leads may give...less side-eye" to the use of injection over @TestVisible annotation. I guess that I'm not as senior (in development -- I definitely am in age) as I'd hoped I might be, so I have to ask what's the issue with @TestVisible?
Aug 28 at 13:50 history edited Derek F CC BY-SA 4.0
added 63 characters in body
Aug 28 at 13:41 history answered Derek F CC BY-SA 4.0