JDBC + DBUnit未找到测试

戴蒙:

我正在尝试为我的DAOImpl课程编写一个测试,只是简单地插入一个查询,但是测试无法正常工作,并给出以下错误:junit.framework.AssertionFailedError: No tests found in ...

无法找到有关此问题的任何信息。

测试类别:

import org.dbunit.Assertion;
import org.dbunit.DBTestCase;
import org.dbunit.PropertiesBasedJdbcDatabaseTester;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.ITable;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.junit.jupiter.api.Test;
import test.database.dao.DaoFactory;
import test.database.dao.interfaces.CoursesDao;
import test.models.Course;

import java.io.File;

import static org.junit.jupiter.api.Assertions.*;

public class CoursesDaoImplTest extends DBTestCase {

public CoursesDaoImplTest(String name) {
    super(name);
    System.setProperty(PropertiesBasedJdbcDatabaseTester.DBUNIT_DRIVER_CLASS, "org.postgresql.Driver");
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_CONNECTION_URL, "jdbc:postgresql://localhost:5432/school" );
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_USERNAME, "school_admin" );
    System.setProperty( PropertiesBasedJdbcDatabaseTester.DBUNIT_PASSWORD, "admin" );
}

@Override
protected IDataSet getDataSet() throws Exception {
    return new FlatXmlDataSetBuilder().build(new File(getClass().getClassLoader()
            .getResource("/school-data.xml").getFile()));
}

@Test
public void TestAdd_ShouldAddCourse_WhenInputNewCourse() throws Exception {

    Course course = new Course("Archery", "Description");

    CoursesDao coursesDao = DaoFactory.getCoursesDao();
    coursesDao.add(course);

    IDataSet databaseDataSet = getConnection().createDataSet();
    ITable actualTable = databaseDataSet.getTable("courses");

    IDataSet expectedDataSet = new FlatXmlDataSetBuilder().build(new File(getClass().getClassLoader()
            .getResource("/coursesDaoImplTest-add-expected.xml").getFile()));
    ITable expectedTable = expectedDataSet.getTable("courses");

    Assertion.assertEquals(expectedTable, actualTable);
}

}

杰夫:

DBTestCase是一个JUnit 4类,您正在使用JUnit 5中的@Test。需要确定要使用的版本并进行相应的更新。

此外,不要扩展dbUnit测试类,而应使用composition。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

未找到加载JDBC org.postgresql.Driver的类

基本 Spring JDBC 应用程序,未找到 JdbcTemplate bean

未找到测试NG

junit:未找到测试

PyCharm“未找到测试”

Hive-JDBC:通过Hive-JDBC连接从Hive表中获取数据时,未找到行异常

org.hibernate.engine.jdbc.spi.SqlExceptionHelper - 功能“在”未找到; SQL语句

java.sql.SQLException:未找到适合jdbc:sqlserver://的驱动程序-基于Java的Azure函数

sql jdbc getgenickeys返回未找到列“ id”,列类型未知

Spring应用程序监听器-ContextRefreshedEvent java:comp / env / jdbc / db未找到

休眠-未找到适用于jdbc的驱动程序:mysql // *

Clojure JDBC ODBC“未找到数据源名称且未指定默认驱动程序”

com.microsoft.sqlserver.jdbc.SQLServerDriver类未找到异常(新)

如何在不遇到NoSuchTableException的情况下使用具有普通JDBC和HSQLDB的DBUnit进行测试?

找到预绑定的JDBC连接

测试中未找到 RadioListTile

Android Studio“未找到测试”

未找到元素,继续测试

笑话单元测试-未找到测试

Android检测的测试未找到测试

NUnit无法建立测试-未找到测试

VSTS 测试组件 - 未找到测试组件

Google测试未找到任何测试

无法完成架构更新:org.h2.jdbc.JdbcSQLException:未找到表“ PG_CLASS”;SQL语句

使用JDBC驱动程序时,timescaledb drop_chunks()调用失败并出现函数未找到错误

Hibernate异常:找到预绑定的JDBC连接

Spring dao测试未找到休眠类

Laravel测试未找到模拟对象方法

Spring Boot WebFlux测试未找到MockMvc