【问题标题】:JDBC + DBUnit no tests foundJDBC + DBUnit 未找到测试
【发布时间】:2020-05-13 19:05:28
【问题描述】:

我正在尝试为我的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);
}

}

【问题讨论】:

    标签: java testing jdbc dbunit


    【解决方案1】:

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

    此外,不要扩展 dbUnit 测试类,而是使用组合。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 2021-09-24
      • 1970-01-01
      • 2011-06-15
      • 2010-12-04
      • 2016-09-02
      • 1970-01-01
      相关资源
      最近更新 更多