asp.net mvc - Unit Testing in MVC not creating/accessing database -
asp.net mvc - Unit Testing in MVC not creating/accessing database -
i have solution mvc project containing services project on top of core project.
i added unit tests project , referenced core , services - i'm trying test services.
i have basic phone call in test:
public class crudtests { private readonly setservices _setservice = new setservices(); [testmethod] public void testmethod() { _setservice.createset("test set", "test set details", null);
which ends failing because test can't connect database. config has this:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionstrings> <add name="defaultconnection" connectionstring="data source=.\;initial catalog=project.services.tests;integrated security=sspi;attachdbfilename=|datadirectory|\project.services.tests.mdf" providername="system.data.sqlclient" /> </connectionstrings> </configuration>
i've tried creating database project.services.tests , running, this:
message=database 'c:\program files\microsoft sql server\mssql11.mssqlserver\mssql\data\app.services.tests.mdf' exists. take different database name. cannot attach file 'c:\projects\app\app\services.tests\bin\debug\services.tests.mdf' database 'app.services.tests'. source=.net sqlclient info provider errorcode=-2146232060 class=16 linenumber=65536 number=1801 procedure="" server=.\ state=2 stacktrace:
i tried deleting database , letting test it's thing, , this:
a file activation error occurred. physical file name '\project.services.tests.mdf' may incorrect. diagnose , right additional errors, , retry operation.
how can working properly?
in unit testing must test code without dependency such database or file scheme etc. unit test means testing part of code independently. if want test code integration database must create integration test. means should create initializing database usage before running test , tear downwards diposing resources after finishing tests.
maybe link help more understand difference between unit test , integration test
asp.net-mvc asp.net-mvc-3 unit-testing asp.net-mvc-4 mstest
Comments
Post a Comment