Populating a MySQL database with values

I have a locally installed MySQL server on my laptop and I want to use the information in it for a unit test, so I want to create a script to automatically create all the data. I use MySQL Workbench, which already generates tables (from the model). Can I use it or another tool to create an automatic script to populate it with data?

EDIT: Now I see that I did not understand. I have significant data for unit test. When I said “generate all data automatically”, I meant that the tool should use the meaningful data that I have in my local database and create a script to generate the same data in other developer databases.

+5
source share
2 answers

The most useful unit tests are those that reflect the data that you expect or see in practice. Pumping your circuit full of random bits does not replace carefully processed test data. Since @McWafflestix suggested mysqldump is a useful tool, but if you want something simpler, consider using LOAD DATA with INFILE , which populates a table from CSV,

Some other things to think about:

  • Test the database in a known state. Wrap all the tests of the database interaction block in transactions that are always rolled back.
  • dbunit, .

Java, dbUnit :

  • XML API-, .
  • . , , , . , (.. ).
+1

( )

CREATE TABLE #t(c1 int DEFAULT 0,c2 varchar(10) DEFAULT '-')
GO
--This insert 50 rows in table
INSERT INTO #t( c1, c2 )
DEFAULT VALUES
GO 50

SELECT * FROM #t
DROP TABLE #t
0

All Articles