参数化单元测试

2024-01-08 08:58:41 浏览数 (2)

屋小巧安置,田少勤耕耘,妻贱合夫心,此乃真富裕。——富兰克林

今天进行streampark参数化单元测试,用来测试多个数据库下的兼容情况

代码语言:javascript复制
package org.apache.streampark;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.streampark.console.core.entity.Application;
import org.apache.streampark.console.core.mapper.ApplicationMapper;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;

/**
 * MapperTest
 */
class MapperTest {

    @ParameterizedTest
    @ValueSource(strings = {"pgsql", "mysql", "h2"})
    void test(String profile) {
        System.setProperty("spring.profiles.active", profile);
        try (ConfigurableApplicationContext context = new SpringApplicationBuilder(StreamParkConsoleBootstrap.class).profiles(profile).run()) {
            ApplicationMapper applicationMapper = context.getBean(ApplicationMapper.class);
            Application app = new Application();
            app.setProjectName("test");
            Assertions.assertDoesNotThrow(() -> applicationMapper.page(new Page<>(), app));
        }
    }
}

代码放到了这里:

streampark-mapper-test: streampark mapper测试,用于兼容多数据库

0 人点赞