SuperAPI AI Directory

Testing Patterns

Testing & quality

View repository

Updated 10-16 05:58

About this skill

<test_phase>Act: Execute the code under test</test_phase>

total = cart.calculate_total

<test_phase>Assert: Verify expected outcomes</test_phase>

assert_equal 0, total
<bdd_step>When: Action or trigger</bdd_step>

when_the_user_calculates_total

<bdd_step>Then: Expected outcome</bdd_step>

then_the_total_should_be_zero
  def save(key, value)
    @data[key] = value
  end

  def find(key)
    @data[key]
  end
end
<note>JS/TS (fast-check)</note>
fc.assert(
  fc.property(fc.array(fc.integer()), (arr) =>
    deepEqual(arr, reverse(reverse(arr)))
  )
)

<best_practices> Test happy path first Start with the normal, expected flow before edge cases test_userLogin_withValidCredentials_succeeds test_userLogin_withInvalidPassword_fails test_userLogin_withLockedAccount_fails

  <note>Unverifiable: state it, do not fabricate</note>

  expected total: unverified -- requires-analysis
</example>
  def teardown
    @database.clear
  end
</example>
  <note>Bad: Unclear purpose</note>

  test_user_reg_1
</example>
  <note>Avoid: Multiple unrelated assertions</note>

  test_userCreation
    user = create_user
    assert_equal "member", user.role
    assert_not_nil user.email
    assert_true user.active
  end
</example>
  <bad_example>Bad</bad_example>

  test_userValidation_withValidAge_succeeds
    user = User.new(age: 25)
    assert user.valid?
  end
</example>

<anti_patterns> Testing implementation details instead of behavior Focus on testing observable behavior and outcomes, not internal implementation details. Test what the code does, not how it does it.

<tooling_traps> Environment- and toolchain-level failure modes that silently invalidate otherwise well-designed tests. These are not test-design mistakes; they are traps in how the runner, compiler, or server is wired, and each can make a green result meaningless or a red result misleading.

<error_escalation inherits="core-patterns#error_escalation"> Minor coverage gap in non-critical path Test flakiness detected Critical path lacks test coverage Tests reveal security vulnerability </error_escalation>

<related_agents> Locate relevant code patterns Review output consistency </related_agents>

<related_skills> Use to define test requirements and acceptance criteria Use to implement tests as part of feature development workflow Use when debugging test failures or flaky tests </related_skills>