UnitAuto Automated Unit Testing Platform

repository·master·Indexed 42 days ago

https://github.com/tommylemon/unitauto

A zero-code, machine learning-powered automated unit testing platform that validates correctness, availability, and performance of methods and functions. It supports multiple languages including Java, Go, Python, C++, and Android, operating at runtime to eliminate the need for manual test code or complex mock environments.

Tokens
11.1K
Snippets
42
Records
52
Agent score
53%

What's inside UnitAuto

  1. Overview of UnitAuto

    master

    UnitAuto is a machine learning-powered, zero-code automated unit testing platform. It is designed to test the correctness, availability, and performance of methods and functions without requiring the developer to write manual test code (no logic code or annotations needed).

    Key capabilities include:

    • Zero-Code Testing: Automatically reads method properties, injects parameters, and captures return values or member variable changes.
    • Runtime Testing: Operates at runtime, eliminating the need for complex Mock environments (like Application or Context in Android).
    • Automated Validation: Uses machine learning models or pre/post-state comparisons to automatically assert results.
    • Asynchronous Support: Automatically records and handles callback processes for asynchronous methods.
    • Multi-Platform: Supports Java, Kotlin, Go, Python, C++, and Android.
  2. Supported testing patterns in unitauto-go

    master

    The unitauto-go library supports several Go-specific execution patterns for automated testing:

    • Sync pure functions: Testing standard synchronous functions.
    • Struct member functions: Testing methods attached to specific struct instances.
    • Goroutine functions: Testing asynchronous functions running in goroutines.
    • Async callback functions: Testing functions that utilize asynchronous callbacks.
  3. Supported function types in unitauto-py

    master

    The unitauto-py library supports testing various Python function patterns, including:

    • Synchronous pure functions: Standard functions without side effects.
    • Class member functions: Methods defined within a class.
    • Async/Await coroutines: Asynchronous functions using the async and await syntax.
    • Asynchronous callback functions: Async functions used as callbacks.
  4. Install unitauto-springboot via Maven

    master

    To use the unitauto-springboot library in a Maven project, you must first add the JitPack repository to your pom.xml and then declare the dependency. Use the version LATEST to always pull the most recent build.

    <!-- 1. Add JitPack repository -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    
    <!-- 2. Add dependency -->
    <dependency>
        <groupId>com.github.TommyLemon</groupId>
        <artifactId>unitauto-springboot</artifactId>
        <version>LATEST</version>
    </dependency>
  5. Install unitauto-jar via Gradle

    master

    To use the unitauto-jar library in a Gradle project, add the JitPack repository to your root build.gradle file within the allprojects block, and then add the dependency to your specific module's (e.g., app) build.gradle file.

    // 1. Add JitPack repository to root build.gradle
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    // 2. Add dependency to module build.gradle (e.g., app/build.gradle)
    dependencies {
        implementation 'com.github.TommyLemon:unitauto-jar:latest'
    }
  6. Install unitauto-jar via Maven

    master

    To use the unitauto-jar library in a Maven project, you must first add the JitPack repository to your pom.xml, then add the unitauto-jar dependency. Use the version LATEST to always pull the most recent build.

    <!-- 1. Add JitPack repository -->
    <repositories>
        <repository>
            <id>jitpack.io</id>
            <url>https://jitpack.io</url>
        </repository>
    </repositories>
    
    <!-- 2. Add unitauto-jar dependency -->
    <dependency>
        <groupId>com.github.TommyLemon</groupId>
        <artifactId>unitauto-jar</artifactId>
        <version>LATEST</version>
    </dependency>
  7. Install unitauto-springboot via Gradle

    master

    To use the unitauto-springboot library in a Gradle project, add the JitPack repository to your root build.gradle file within the allprojects block, and then add the dependency to your specific module's build.gradle (e.g., the app module).

    // 1. In root build.gradle
    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }
    
    // 2. In module build.gradle (e.g., app/build.gradle)
    dependencies {
        implementation 'com.github.TommyLemon:unitauto-springboot:latest'
    }
  8. Register functions and structs for testing in Go

    master

    Due to Go's reflection limitations, you must explicitly register the functions and struct instances you wish to test.

    Instead of writing registration code manually, you can use the UnitAuto-Admin web interface:

    1. Navigate to the [View/Sync doc] setting item in the UnitAuto-Admin frontend.
    2. Generate the required code (referred to as ginCode).
    3. Copy and paste the generated code into your project under test.
  9. Integrate UnitAuto into an Android App

    master

    To integrate UnitAuto into an Android project, follow these steps:

    1. Add the UnitAuto-Apk Module

    Import UnitAuto-Apk into your project's app module directory. Update your settings.gradle:

    include ':UnitAuto-Apk'

    Then, add the dependency in your app/build.gradle:

    dependencies {
        api project(':UnitAuto-Apk')
    }

    2. Initialize UnitAuto

    Call UnitAutoApp.init(this) within your Application class's onCreate method:

    @Override
    public void onCreate() {
        super.onCreate();
        UnitAutoApp.init(this);
    }

    3. Register the Admin Activity

    In your AndroidManifest.xml, register the UnitAutoActivity so the management interface can be accessed:

    <activity
        android:name="unitauto.apk.UnitAutoActivity"
        android:launchMode="singleInstance">
    </activity>

    4. Create an Entry Point

    Add a button or UI element in your app to launch the UnitAuto interface (typically for DEBUG builds):

    public void onClickUnit(View v) {
        startActivity(UnitAutoActivity.createIntent(this));
    }
    // settings.gradle
    include ':UnitAuto-Apk'
    
    // app/build.gradle
    dependencies {
        api project(':UnitAuto-Apk')
    }
    // Application.java
    @Override
    public void onCreate() {
        super.onCreate();
        UnitAutoApp.init(this);
    }
    <!-- AndroidManifest.xml -->
    <activity
        android:name="unitauto.apk.UnitAutoActivity"
        android:launchMode="singleInstance">
    </activity>
  10. Deploy the UnitAuto Admin Management Tool

    master

    The UnitAuto-Admin tool provides a web interface to view, upload, execute, and manage test cases for your backend or mobile projects.

    Local Deployment

    1. Download the source code and unzip it.
    2. Open UnitAuto-Admin/index.html in a browser (Chrome or Firefox are recommended; Safari, Edge, and IE may have compatibility issues).

    Configuration

    1. Set Server URL: In the top-right settings, enter your project's base URL (e.g., http://192.168.0.102:8080).
    2. Login: Use the default admin credentials:
      • Username: 13000082001
      • Password: 123456
    3. Sync Methods: Click "View/Sync Method Documentation" (查看、同步方法文档) to import methods from your running project.

    Connectivity Requirements

    • Mobile Testing: If testing an Android/iOS app, the mobile device and the computer running the Admin tool must be on the same local network (LAN).
    • Simulators: If using an emulator, ensure it is on the same network and accessible via http://localhost:port.