OpenParable
Skip to content
← Back to skills

Unit Test Patterns

Testing & Quality
unit-test-patterns

Unit Test Patterns is an Agent Skill for testing & quality published in the analogdevicesinc/scopy repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.

Code patterns and examples for Scopy IIOWidget unit tests. Covers standard helpers, data-driven testing, and complex multi-step scenarios. Auto-loads when creating or reviewing `*_Unit_test.js` files.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
Inspect the Agent Skill at https://github.com/analogdevicesinc/scopy/blob/HEAD/tools/scopy_dev_plugin/skills/unit-test-patterns/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/unit-test-patterns, but wait for my approval before writing files or running scripts.

Copying this prompt does not install or run the skill. Review third-party files before use.

Unit Test Patterns for Scopy IIOWidget Tests

This skill provides code patterns for generating and reviewing JS unit tests that validate IIOWidget attributes in Scopy plugins. All examples are from the AD9371 reference implementation.

Standard Helper Functions

These helpers test individual widget attributes. Every unit test file must define and use them.

PatternFileWidget TypeDescription
testRangetest-range.mdRange/SpinboxWrite min/max/mid, verify readback with tolerance
testCombotest-combo.mdCombo/DropdownIterate valid options, verify exact match
testCheckboxtest-checkbox.mdCheckbox/ToggleToggle 0/1, verify readback
testReadOnlytest-readonly.mdRead-OnlyVerify value is non-empty
testConversiontest-conversion.mdAPI + WidgetValidate API scaling vs raw widget value
testBadValueRangetest-bad-value-range.mdRange boundaryVerify above-max/below-min clamping
testBadValueCombotest-bad-value-combo.mdCombo boundaryVerify invalid option rejection
testCalibrationFlagtest-calibration-flag.mdCalibration toggleTest enable/disable via API getter/setter
runDataDrivenTestsdata-driven-tests.mdBatch dispatchRun array of test descriptors through helpers

Complex Test Patterns

Multi-step scenarios that test functionality beyond single-widget read/write. Each pattern includes: when to use, API signature trigger, and complete code example.

PatternFileTrigger
Calibration Flowcomplex-calibration-flow.mdcalibrate() exists in API
Profile Loadingcomplex-profile-loading.mdloadProfile() exists
Gain Mode Interactioncomplex-gain-mode-interaction.mdgetXxxGainControlMode() + setXxxHardwareGain()
State Transitionscomplex-state-transitions.mdgetEnsmMode()/setEnsmMode()
DPD Operationscomplex-dpd-operations.mddpdReset() + getDpdStatus()
Channel Independencecomplex-channel-independence.mdSetter with int channel, count > 1
Phase Rotationcomplex-phase-rotation.mdgetPhaseRotation()/setPhaseRotation()
Frequency Tuningcomplex-frequency-tuning.mdGetter/setter with Hz-to-MHz conversion
UDC LO Splittingcomplex-udc-lo-splitting.mdhasUdc()/getUdcEnabled()
Refresh Cyclecomplex-refresh-cycle.mdrefresh() exists

File Structure

ReferenceFile
File Structure & Boilerplatefile-structure.md

Key Rules

  1. Every setter must be followed by msleep(500) — no exceptions
  2. Every test must save and restore original values — in all exit paths
  3. Use standard helpers — do not write ad-hoc read/write/compare for standard widget types
  4. Use runDataDrivenTests() — for sections with 3+ widgets of the same type
  5. UID format: UNIT.<SECTION>.<ATTRIBUTE_NAME> — uppercase, dots as separators
  6. Widget key format: <device-name>/<channel>/<attribute> or <device-name>/<attribute>