This unit test question raised another thing that bothered me. I went back and forth in three ways to run unit tests when I hit the database.
I know that option 1 is the “right” way to do unit tests, but out of the three, maybe the option I used the least (although the last projects were with IOC, so the door is open for me). I understand that a lot depends on what exactly is being mocked and what is being tested, but what am I missing here?
If the context helps, I am in the C # store, creating my own applications, only a few developers.
, , IQueryable<T>. , : List<T> AsQueryable. , moq .
IQueryable<T>
List<T>
AsQueryable
, , (, ). , Moles , , . IOC, .
( 1). .
( 2), ( 2). ? , ( O/R, ..), .
, ( .NET, NUnit SqlServer ):
using System.Transactions; using NUnit.Framework; namespace Crown.Util.TestUtil { [TestFixture] public class PersistenceTestFixture { public TransactionScope TxScope { get; private set; } [SetUp] public void SetUp() { TxScope = new TransactionScope(); } [TearDown] public void TearDown() { if (TxScope != null) { TxScope.Dispose(); TxScope = null; } } } }
.
. , , , . API, , DAO, ?
. , , . , hsql, . , . , , , .
mocks , , . . -, mocks, . , , , , , .
, . , , - , . , 100% .
, , ?
If you separate your business-level and service-level logic from your persistence code, you should easily isolate the code you want to use unit test without having a database.
One of the most important principles of unit testing is isolation and testing separately. When you have a clear idea of how to do this, unit testing is easy. When you do not, unit testing becomes difficult.
Source: https://habr.com/ru/post/1751887/More articles:JQuery speed: which one is faster, {ul # parent li} or {li.child}? - jqueryHow to write to the console in Google App Engine (JAVA)? - javaLocal thread storage - c ++What are the data types of social integration platforms (facebook, twitter, openid) ids? - typesHow can I programmatically get the primary key for an object (in Entity Framework 4)? - repositoryIs there a way to visualize a stack of activity (actions in memory) on Android? - androidCan I programmatically turn on the Macbook Pro keyboard backlight for individual keys? - keyboardAccess methods for collections in Java - javaReference to variables from anonymous classes in Java - javaHow to read comments in the Android Market? - androidAll Articles