Testing / Karate Framework Interview questions
When should you use callonce instead of call?
call executes the referenced feature (or function) every time that step is reached, once per scenario. callonce executes it exactly once for the entire test run (or the entire feature, depending on scope) and caches the result, reusing that cached result for every subsequent scenario instead of re-running the setup.
Background: * def authResult = callonce read('login-once.feature') * def authToken = authResult.token
The right choice depends on whether the called logic produces something safely reusable across scenarios or something that genuinely needs to be fresh each time. An expensive, slow-changing setup step, like obtaining an OAuth token that's valid for an hour, is a good callonce candidate: running it once and reusing the token across dozens of scenarios saves significant time. A setup step that must produce fresh, scenario-specific state, like creating a new test record each scenario needs to manipulate independently, should stay as a regular call, since sharing that result across scenarios would cause them to interfere with each other.
More Related questions...