I have written some tests for some .net code that invites calls to my SQL server. Using the System.Transactions
is an excellent choice to roll back any amendments to the database, which results in me knowing that some netwists suggest that I want to duplicate the database, but I I'm not going through that road; This is not strictly a pure unit test.
When I write and run several tests, it works as expected. I just put the code to start and cancel Test Setdown methods and cancel. It seemed like a great solution.
However, I have the problem that when I try to run these 100 tests, many of them will throw exceptions, though they can not connect to SQL Server running one-by-one Pass time To make things even worse, tables in my database are locked multiple times when I run my test, I have to manually remove the lock to ask for my DBA.
As many of you will know, that will run on a development workstation, using a TransactionScope code (as this test is running) against a SQL server. NET Framework Using MSDTC
Here's a code sample to describe what I'm doing:
; TestInitialize () & gt; Public Sub MyTestInitialize () _scope = new System.Transactions.TransactionScope (_ System.Transactions.TransactionScopeOption.Required, New period (0, 2, 0)) End Sub
& lt; TestCleanup () & gt; Public sub MyTestCleanup () _scope.Dispose () end sub & amp; TestMethod () & gt; Public All CurrentProgram UserGate_USIRID () String Dim Current Program as User Programmable Program Session Program Segment Current DCMUIIRID = Convert as Integer Dim Dission as IDID. ToInt32 (_ SqlHelper.ExecuteScalar (testDcmaConnString, System.Data.CommandType.Text, _ "In the program_USERS (username, first name, last name) Select" & amp; _ "value ('GuitarPlayer', 'Bob', 'Marley')" & amp; _ "IDENT_CURRENT ( 'Program_users') ") _) ProgramSessionId = session.getCurrentSession () session.WriteUserParam (" Program ", ProgramSessionId," user id ", CurrentProgramUserId.ToString (), testSource, testConnString) dim readValue integer readValue = session.User.UserID Assert.AreEqual (CurrentProgramUserId, readValue) End as Sub
can see as you are, there's nothing particularly fancy I have only one test method which my database Is going to write some stuff, which I want to find my way is only one example; There are many other tests like this.
The logic of my tests seems to be what may be due to not only failing my tests, but users can be excluded from the tables?
I found the problem The method I was testing uses an SqlDataReader
object. Obviously, the code should be called before the closed ()
method
Just add mySqlDataReader.Close ()
Under the test, the problem is fixed at the end. Apart from this, the test method to test this particular method was data-based with more than 100 test cases, so it explains how I could run out of the connection.
Comments
Post a Comment