What a good practice for java agile integration testing DAO & # 8594; Database?

What is the current good practice for flexibly testing DAO integration with a real database schema in the Java landscape?

(According to agile, I mean what is the most streamlined, automated, and simplest solution to this problem).

I hope to achieve automation of tests that prove that the level of data access is integrated without problems with real working database instances. It is important that we test our own SQL for specific vendor vendors. I.E. if we write T-SQL, we want to test SQL Server.

Should one database be allocated for all running tests, but without commits? Or should each test environment have a dedicated database?

How do people deal with tuning and disruption? Is DBUnit Still Popular? How to help Spring?

+3
source share
4 answers

It is important that we test our custom SQL for specific vendor vendors.

So you must create a test suite for each vendor database.

@RunWith(Suite.class)
@Suite.SuiteClasses({})
public class SQLServerTestSuite {

    @BeforeClass
    public static void setUpClass() throws Exception {

    }

    @AfterClass
    public static void tearDownClass() throws Exception {
        // clean database
    }

}

Should one database be allocated for all running tests, but without commits?

It is recommended that you execute SQL commands , but with a rollback command , because when using commit, you can change the state of the current test, as well as change the state of other tests. Otherwise, you may be dealing with unexpected behavior.

sandbox. , , , .

?

public class PersonTest {

    @Before
    public void setUp() {
        // set up state to run the test
    }

    @After
    public void teardown() {
       // Transaction rollback
    }

}

, , , ,

DBUnit ?

DBUnit XML , . , DBUnit . , , . , .

Spring?

Spring (SqlParameterSource), plain jdbc XML ,

<?xml version="1.0" encoding="UTF-8"?>
<queries>
    <query name="PERSON_BY_ID">
        <![CDATA[
            select 
                *
            from 
                PERSON
            where
                PERSON.ID = :integerId
        ]]>
    </query>
</queries>

. JavaScript-, . ,

public class SQLServerQuery {

    public static final String PERSON_BY_ID = "PERSON_BY_ID";

}

, < < =. , , , , . , .

+3

, DAO , ORM QL, . HQL JDBC SQL. , , / . , " ", HSQLDB, .

"Spring Test" IoC, , , , , ... , ( , , unit test , unit test).

, , . , , , , .

+3

, ( ) , , . - , . DBUnit - .

, . , . Dbunit, , .

, , - .

+1

, , , ? Junits Hudson . DAO, , , ..

DAO - . JDBC - , . , ? SQL DAO?

0

Source: https://habr.com/ru/post/1766130/


All Articles