Test patterns

From weisser-dev/awesome-opencode · View interactive version

Test patterns is an AI agent skill from the GitHub repository weisser-dev/awesome-opencode. Generate tests following project conventions with proper patterns for unit, integration, and e2e testing

How to use this skill

Skill file

What I do

When to use me

Use this skill when you need to write tests for new or existing code.

This skill first analyzes existing tests to match the project's style.

Process

  1. Discover: Find existing tests to understand patterns
  1. Analyze: Read the code under test
  1. Generate: Write tests following discovered patterns

Test Patterns by Framework

JavaScript/TypeScript (Vitest/Jest)

describe("ModuleName", () => {
  // Setup
  beforeEach(() => { /* ... */ })

  describe("methodName", () => {
    it("should return expected value for valid input", () => {
      // Arrange
      const input = createTestInput()
      // Act
      const result = methodName(input)
      // Assert
      expect(result).toEqual(expectedValue)
    })

    it("should throw for invalid input", () => {
      expect(() => methodName(null)).toThrow(ExpectedError)
    })
  })
})

Python (Pytest)

class TestModuleName:
    @pytest.fixture
    def setup(self):
        return create_test_fixture()

    def test_method_returns_expected_for_valid_input(self, setup):
        result = method_name(setup)
        assert result == expected_value

    def test_method_raises_for_invalid_input(self):
        with pytest.raises(ExpectedError):
            method_name(None)

Java (JUnit 5)

@DisplayName("ModuleName Tests")
class ModuleNameTest {
    @BeforeEach
    void setUp() { /* ... */ }

    @Test
    @DisplayName("should return expected value for valid input")
    void methodName_validInput_returnsExpected() {
        var result = moduleName.methodName(validInput);
        assertEquals(expected, result);
    }

    @Test
    @DisplayName("should throw for invalid input")
    void methodName_invalidInput_throws() {
        assertThrows(ExpectedException.class,
            () -> moduleName.methodName(null));
    }
}

Coverage Targets

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.