mcpbeat Sign in

Counterexample To Test Generator Agent Skill

Automatically generates executable test cases from model checking counterexample traces. Translates abstract counterexample states and transitions into concrete test inputs, execution steps, and assertions that reproduce property violations. Use when working with model checker outputs (SPIN, CBMC, NuSMV, TLA+, Java PathFinder, etc.) and needing to create regression tests, validate bug fixes, or reproduce verification failures in executable test suites.

8k tokens
context cost
the whole folder, loaded on every use
8
files
ships runnable scripts
0
copies elsewhere
how many repositories repackaged it
141
stars on the repo
on the repository, not the skill itself

Install

one command, takes just this skill from the repository
npx skills add https://github.com/ArabelaTso/Skills-4-SE --skill counterexample-to-test-generator

The instruction itself

12 sections, as written by the author

Counterexample To Test Generator

Overview

This skill transforms counterexample traces from model checkers into executable test cases that reliably reproduce property violations. It bridges formal verification and testing by mapping abstract states to concrete values and generating runnable tests with clear traceability from counterexample steps to test logic.

Workflow

Step 1: Analyze Inputs

Gather and understand the counterexample trace and program:

  • Identify the model checker format: Determine which tool produced the counterexample (SPIN, CBMC, NuSMV, TLA+, JPF, etc.). See references/model_checker_formats.md for format details.
  • Extract key information:
  • Initial state values
  • Sequence of transitions/steps
  • Variable values at each step
  • Property violation point
  • Error condition or assertion failure
  • Understand the program structure:
  • Entry points and function signatures
  • Input parameters and their types
  • State variables involved in the trace
  • Control flow relevant to the counterexample

Step 2: Map Abstract States to Concrete Values

Translate the counterexample's abstract representation into concrete test inputs:

  • Determine concrete values for abstract state variables:
  • Map symbolic values to concrete instances
  • Resolve non-deterministic choices to specific values
  • Handle ranges and constraints from the model
  • Identify input sequences:
  • Extract the sequence of function calls or operations
  • Determine parameter values for each call
  • Identify timing or ordering constraints
  • Handle environment assumptions:
  • External inputs or system calls
  • Concurrency or scheduling decisions
  • Resource states (files, network, memory)

Step 3: Generate Test Structure

Create the test case framework in the target language:

  • Choose test framework based on the program language:
  • C/C++: Google Test, CUnit, Check
  • Java: JUnit, TestNG
  • Python: pytest, unittest
  • C#: NUnit, xUnit
  • Structure the test:
  • Setup phase: Initialize state to match counterexample start
  • Execution phase: Replay the counterexample sequence
  • Assertion phase: Verify the property violation occurs
  • Add traceability comments: Map each test step to counterexample steps for debugging and maintenance.

Step 4: Implement Test Logic

Write the executable test code:

  • Setup code:
   // Initialize variables to counterexample initial state
   // Set up test fixtures or mocks
   // Configure environment (if needed)
  • Execution sequence:
   // Step 1 (CE line X): [description]
   // Execute operation with concrete values

   // Step 2 (CE line Y): [description]
   // Execute next operation
  • Assertions:
   // Verify property violation (CE line Z)
   // Assert expected failure condition
   // Check final state matches counterexample

Step 5: Generate Output

Produce the complete test case with documentation:

  • Test file: Complete, compilable/runnable test code
  • Mapping document: Table linking counterexample steps to test lines
  • Execution instructions: How to compile and run the test
  • Expected behavior: What the test should demonstrate (failure reproduction)

Example Workflow

Input: SPIN counterexample showing a deadlock in a concurrent system

Output:

// test_deadlock.c - Reproduces deadlock from SPIN counterexample trail
#include <pthread.h>
#include <assert.h>

// Counterexample mapping:
// CE Step 1-2: Thread 1 acquires lock A
// CE Step 3-4: Thread 2 acquires lock B
// CE Step 5: Thread 1 waits for lock B (blocks)
// CE Step 6: Thread 2 waits for lock A (deadlock)

void* thread1_func(void* arg) {
    pthread_mutex_lock(&lock_a);  // CE Step 1
    sleep(1);                      // CE Step 2 (timing)
    pthread_mutex_lock(&lock_b);  // CE Step 5 (blocks)
    // ... rest of test
}

void test_deadlock_scenario() {
    // Setup: Initialize locks (CE initial state)
    pthread_mutex_init(&lock_a, NULL);
    pthread_mutex_init(&lock_b, NULL);

    // Execute: Create threads in counterexample order
    pthread_create(&t1, NULL, thread1_func, NULL);
    pthread_create(&t2, NULL, thread2_func, NULL);

    // This test will hang, demonstrating the deadlock
    pthread_join(t1, NULL);  // Will timeout
}

Best Practices

  • Minimize test complexity: Generate the simplest test that reproduces the violation
  • Preserve causality: Maintain the exact sequence from the counterexample
  • Make violations obvious: Use clear assertions and error messages
  • Add context: Include comments explaining the property being violated
  • Handle non-determinism: Document any assumptions made when concretizing values
  • Test the test: Verify the generated test actually fails as expected

Common Challenges

Challenge: Counterexample uses symbolic values without concrete bounds

Solution: Use representative values from the domain, document the choice

Challenge: Trace involves complex timing or scheduling

Solution: Use synchronization primitives or explicit delays to enforce ordering

Challenge: Program state is partially specified in counterexample

Solution: Initialize unspecified variables to default/neutral values

Challenge: Counterexample is very long

Solution: Identify the minimal prefix that still triggers the violation

References

  • references/model_checker_formats.md: Detailed format specifications for common model checkers
  • assets/test_templates/: Test framework templates for various languages

Other skills for the same job

different authors, same section of the catalogue
Webapp Testing
by anthropics
vendor ×12

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

6k tokens scripts
Finishing A Development Branch
by ZhanlinCui
×7

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup

1k tokens
Test Driven Development
by w95
×7

Use when implementing any feature or bugfix, before writing implementation code

2k tokens
Systematic Debugging
by ratacat
×7

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes

10k tokens scripts
Verification Before Completion
by ZhanlinCui
×6

Use when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always

1k tokens
Backtest Expert
by BaggaT236
×3

Expert guidance for systematic backtesting of trading strategies. Use when developing, testing, stress-testing, or validating quantitative trading strategies. Covers "beating ideas to death" methodology, parameter robustness testing, slippage modeling, bias prevention, and interpreting backtest results. Applicable when user asks about backtesting, strategy validation, robustness testing, avoiding overfitting, or systematic trading development.

15k tokens scripts
Adaptyv
by christophacham
×3

Cloud laboratory platform for automated protein testing and validation. Use when designing proteins and needing experimental validation including binding assays, expression testing, thermostability measurements, enzyme activity assays, or protein sequence optimization. Also use for submitting experiments via API, tracking experiment status, downloading results, optimizing protein sequences for better expression using computational tools (NetSolP, SoluProt, SolubleMPNN, ESM), or managing protein design workflows with wet-lab validation.

16k tokens
Aeon
by christophacham
×3

This skill should be used for time series machine learning tasks including classification, regression, clustering, forecasting, anomaly detection, segmentation, and similarity search. Use when working with temporal data, sequential patterns, or time-indexed observations requiring specialized algorithms beyond standard ML approaches. Particularly suited for univariate and multivariate time series analysis with scikit-learn compatible APIs.

19k tokens

How to use it

Copy the folder

Take arabelatso/counterexample-to-test-generator from the repository into ~/.claude/skills for personal use, or into .claude/skills inside a project.

Check the name does not clash

The agent identifies a skill by the name field in its header. Two skills with the same name cannot sit side by side — one of them will be ignored.