Skip to content

mcunittests是一个Maven开源项目,专注于针对Java后端项目进行自动化单元测试,支持API接口、API高并发及业务数据的自动化单元测试。 mcunittests is an open-source Maven project focused on automated unit testing for Java backend projects. It supports automated unit testing for API endpoints, high-concurrency API scenarios, and business data validation.

License

Notifications You must be signed in to change notification settings

Json031/mcunittests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

112 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcunittests (MC Unit Tests)

Build Status Maven Central Codecov Java support License Codecov


🌍 Language / 语言选择

English | 中文


📖 English

Overview

mcunittests is an open-source Maven project focused on automated unit testing for Java backend projects. It supports automated unit testing for API endpoints, high-concurrency API scenarios, and business data validation.

Installation

Latest Version: 1.0.31

Method 1: Install via Maven Central (Recommended)

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.json031</groupId>
    <artifactId>mcunittests</artifactId>
    <version>1.0.31</version>
    <scope>test</scope>
</dependency>
Method 2: Install via GitHub Packages

Step 1: Configure Maven Repository

Add the GitHub Packages repository configuration in the repositories section of your project's pom.xml:

<repository>
    <id>github</id>
    <name>GitHub Json031 Apache Maven Packages</name>
    <url>https://maven.pkg.github.com/json031/mcunittests</url>
</repository>

Step 2: Add Dependency

Add the following dependency in pom.xml:

<dependency>
    <groupId>io.github.json031</groupId>
    <artifactId>mcunittests</artifactId>
    <version>1.0.31</version>
</dependency>

Step 3: Configure Authentication

Configure GitHub authentication information in the servers section of ~/.m2/settings.xml:

<server>
    <id>github</id>
    <username>your-github-username</username>
    <password>your-github-TOKEN</password>
</server>

Usage Examples

Basic API Test

import io.github.json031.apitests.MCApiTests;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
class YourProjectApplicationTests {

    private MCApiTests mcApiTests = new MCApiTests();

    @Test
    public void testExampleApi() {
        // Replace with actual API endpoint
        String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
        Map<String, Object> param = new HashMap<>();
        param.put("id", 2);
        // Expected slowest response time (in seconds)
        long timeoutSeconds = 5;
        mcApiTests.assertApiRespondsWithinTimeout(apiUrl, HttpMethod.GET, param, null, timeoutSeconds, true);
    }
}

High Concurrency API Test

@Test
public void testApiWithHighConcurrency() {
    String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
    Map<String, Object> param = new HashMap<>();
    param.put("id", 2);
    long timeoutSecondsMillis = 1000;
    int threadCount = 1000;
    HighConcurrencyResult highConcurrencyResult = this.mcHighConcurrencyTests.highConcurrencyTestWithTimeoutMillis(
        apiUrl, threadCount, HttpMethod.GET, param, null, timeoutSecondsMillis, true
    );
    System.out.print("highConcurrencyResult:" + highConcurrencyResult.toString());
}

JSON Validation Test

@Test
public void testIsApiValidJson() {
    String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
    Map<String, Object> param = new HashMap<>();
    param.put("id", 2);
    this.mcApiTests.testApiReturnsValidJson(apiUrl, HttpMethod.GET, param, null, true);
}

Test Results

Test Results

License

This library is licensed under the MIT License.


📖 中文

项目简介

mcunittests 是一个 Maven 开源项目,专注于针对 Java 后端项目进行自动化单元测试,支持 API 接口、API 高并发及业务数据的自动化单元测试。

安装

最新版本: 1.0.31

方式 1:通过 Maven Central 安装(推荐)

pom.xml 中添加以下依赖:

<dependency>
    <groupId>io.github.json031</groupId>
    <artifactId>mcunittests</artifactId>
    <version>1.0.31</version>
    <scope>test</scope>
</dependency>
方式 2:通过 GitHub Packages 安装

步骤 1:配置 Maven 仓库

在项目的 pom.xml 文件的 repositories 中,添加 GitHub Packages 仓库配置:

<repository>
    <id>github</id>
    <name>GitHub Json031 Apache Maven Packages</name>
    <url>https://maven.pkg.github.com/json031/mcunittests</url>
</repository>

步骤 2:添加依赖

pom.xml 中添加以下依赖:

<dependency>
    <groupId>io.github.json031</groupId>
    <artifactId>mcunittests</artifactId>
    <version>1.0.31</version>
</dependency>

步骤 3:配置认证

~/.m2/settings.xmlservers 中,配置 GitHub 的认证信息:

<server>
    <id>github</id>
    <username>your-github-username</username>
    <password>your-github-TOKEN</password>
</server>

使用示例

基础 API 测试

import io.github.json031.apitests.MCApiTests;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.HashMap;
import java.util.Map;

@SpringBootTest
class YourProjectApplicationTests {

    private MCApiTests mcApiTests = new MCApiTests();

    @Test
    public void testExampleApi() {
        // 测试 API 接口地址
        String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
        Map<String, Object> param = new HashMap<>();
        param.put("id", 2);
        // 期望最慢响应时间(秒)
        long timeoutSeconds = 5;
        mcApiTests.assertApiRespondsWithinTimeout(apiUrl, HttpMethod.GET, param, null, timeoutSeconds, true);
    }
}

高并发 API 测试

@Test
public void testApiWithHighConcurrency() {
    String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
    Map<String, Object> param = new HashMap<>();
    param.put("id", 2);
    long timeoutSecondsMillis = 1000;
    int threadCount = 1000;
    HighConcurrencyResult highConcurrencyResult = this.mcHighConcurrencyTests.highConcurrencyTestWithTimeoutMillis(
        apiUrl, threadCount, HttpMethod.GET, param, null, timeoutSecondsMillis, true
    );
    System.out.print("highConcurrencyResult:" + highConcurrencyResult.toString());
}

JSON 验证测试

@Test
public void testIsApiValidJson() {
    String apiUrl = "http://localhost:8088/json031/c/2a-d7b4-8005-a16f-8a95f07011df";
    Map<String, Object> param = new HashMap<>();
    param.put("id", 2);
    this.mcApiTests.testApiReturnsValidJson(apiUrl, HttpMethod.GET, param, null, true);
}

测试结果

测试结果

许可证

本项目基于 MIT License 开源协议。


⬆ Back to Top / 返回顶部

About

mcunittests是一个Maven开源项目,专注于针对Java后端项目进行自动化单元测试,支持API接口、API高并发及业务数据的自动化单元测试。 mcunittests is an open-source Maven project focused on automated unit testing for Java backend projects. It supports automated unit testing for API endpoints, high-concurrency API scenarios, and business data validation.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages