.NET TDD with database and ADO.NET database - integration tests

I use the ADO.NET entity structure and use the AdventureWorks database attached to the local database server. For unit testing, what approaches make people work with the database?

Obviously, the database must be in a predetermined state of change so that the tests can have some isolation from each other ... so I need to be able to run inserts and updates, and then roll back between tests or after a series of tests.

Any tips?

Thank.

+3
source share
5 answers

I faced a similar situation.

. .

( /) , ,

1. ( ), , .

2. .

3. , ?

Ans: SQL, (, , SQL SERVER)

, sqlcmd -i c:\data\runningcripts\InventoryMonthEnd.sql

, sql- (), MSBuild.

MSBuild.

<ItemGroup>
<StoredProcScripts Include="$(RelativeSPDir)/*.sql" />
</ItemGroup>

<Target>
<Exec Command="isql -E -n -b -d DBName -i %(StoredProcScripts.Identity)" Condition="'%(StoredProcScripts.Identity)' != ''"/>
</Target>
+2

, . , , , . , ( * Test.cs), [TestInitialize] Start() [TestCleanup] Finish().

, , unit test , . , EF 4 ObjectContext.CreateDatabase().

+1

:

  • Sandbox /
  • Create all the necessary data in the tests.
  • Delete all test data created by the tests after they pass / fail. Sort oftry...finally
0
source

A really effective way to manage data in your tests is to use a transaction. A colleague introduced this to me, and I later saw that it was used in a number of places (GOOS)

In C #, if you are using TransactionScope and not performing a transaction, you have a really effective way to save things.

0
source

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


All Articles