Skip to content

gay00ung/diff2test-android

Repository files navigation

diff2test-android

Diff-driven Android ViewModel test generation CLI

Detect changed ViewModels, plan tests, generate candidate local unit tests, and verify them with Gradle.

GitHub stars Release Homebrew CLI 1.0 MCP experimental Kotlin 1.9.25 Java 17

English · 한국어

d2t workflow banner

d2t 1.0 focuses on one thing: turning changed Android ViewModels into verifiable local unit tests. The CLI is the primary product. The MCP app remains experimental.

Why d2t

Most Android test generation tools fail in one of two ways:

  • they ignore the actual code diff and generate too much
  • they generate code, but stop before verification

d2t is built around a narrower loop:

  1. detect changed *ViewModel.kt files from git diff
  2. analyze the changed ViewModel surface and collaborators
  3. build a scenario-first TestPlan
  4. generate candidate local unit tests
  5. verify those generated tests with Gradle

That makes it useful as a developer workflow tool, not just a code dump generator.

What 1.0 Includes

d2t 1.0 is intentionally narrow.

  • Diff-driven Android ViewModel local unit test generation
  • Gradle-backed verification of generated tests
  • Bring-your-own API key support
  • OpenAI Responses API support
  • Anthropic Messages API support
  • Gemini GenerateContent API support
  • Custom responses-compatible endpoints
  • Custom chat-completions endpoints
  • Release ZIP and Homebrew distribution

What 1.0 Does Not Promise

  • A transport-bound MCP server
  • Instrumented androidTest generation
  • Compose UI test generation
  • Full end-to-end autonomous repair loops
  • Perfect external classpath symbol resolution in every Android build graph

Install

Homebrew

brew install gay00ung/diff2test-android/d2t

Optional tap flow:

brew tap gay00ung/diff2test-android
brew install d2t

Release ZIP

Download d2t.zip from the latest release:

unzip d2t.zip
cd d2t
./bin/d2t help

Run from Source

git clone https://github.com/gay00ung/diff2test-android.git
cd diff2test-android
./gradlew test
./d2t help

Quick Start

1. Initialize config

d2t init

2. Point d2t at your AI provider

[ai]
enabled = true
provider = "custom"
protocol = "chat-completions"
api_key_env = "LLM_API_KEY"
model = "qwen3-coder-next-mlx"
base_url = "http://127.0.0.1:12345/v1"
connect_timeout_seconds = 30
request_timeout_seconds = 300

3. Confirm config

d2t doctor

4. Generate and verify tests for current changes

d2t auto --ai

If you are running from source, use ./d2t instead of d2t.

Supported AI Protocols

d2t stores only the environment variable name for the API key in ~/.config/d2t/config.toml. Keep the secret itself in your shell environment.

Supported provider/protocol combinations:

  • provider = "openai" with protocol = "responses-compatible"
  • provider = "anthropic" with protocol = "anthropic-messages"
  • provider = "gemini" with protocol = "gemini-generate-content"
  • provider = "custom" with protocol = "responses-compatible"
  • provider = "custom" with protocol = "chat-completions"

Example:

source ~/.zshrc
d2t doctor
d2t auto --ai

How It Works

At a high level:

git diff
  -> changed ViewModel detection
  -> ViewModel analysis
  -> TestPlan generation
  -> AI or deterministic code generation
  -> quality gate
  -> Gradle verification

Important implementation details:

  • d2t does not ask the model to guess from the entire repo blindly
  • the diff and the analyzed ViewModel surface narrow the generation scope first
  • generated tests must pass a built-in quality gate before verification
  • auto generates and verifies in one command
  • --repair enables one bounded repair pass for common import and coroutine-test utility issues

Commands

d2t init [--force]
d2t doctor
d2t scan
d2t plan path/to/SomeViewModel.kt
d2t generate path/to/SomeViewModel.kt --write [--ai|--no-ai] [--strict-ai]
d2t auto [--ai|--no-ai] [--strict-ai] [--model model-name] [--no-verify] [--repair]
d2t verify :module:testTask

Troubleshooting

No changed ViewModel files were detected

  • make sure your current working tree actually contains a modified *ViewModel.kt
  • or pass an explicit file path to plan or generate

AI requests time out

  • increase request_timeout_seconds
  • try a smaller or faster model
  • prefer protocol = "chat-completions" when your gateway handles that path more reliably

Generated tests fail the quality gate

  • the generator produced code that d2t considers too fragile or incomplete
  • this is usually a generation-quality problem, not a Gradle problem
  • retry with a stronger model or add --repair when verification is enabled

Verification fails after generation

  • inspect the generated test under src/test/kotlin/...GeneratedTest.kt
  • run the printed Gradle verification command directly
  • if the failure is import or coroutine utility related, retry with d2t auto --ai --repair

Repository Layout

  • apps/cli: main CLI application
  • apps/mcp-server: experimental MCP-facing catalog scaffold
  • modules/*: engine modules
  • prompts/*: prompt templates and policies
  • fixtures/*: sample app and verification fixtures
  • docs/*: architecture and release docs

Release and Distribution

This repository includes:

The generated archive is written to:

apps/cli/build/distributions/d2t.zip

Product Boundaries

The CLI is the stable surface.

The MCP app is still experimental:

  • it is useful as a catalog scaffold
  • it is not yet positioned as a production transport-bound MCP server

For the current release gate and roadmap:

About

Diff-driven Android ViewModel test generation CLI with AI-assisted planning, generation, and Gradle verification.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages