Anatomy of SQL Server article 6 avoid regressions (translated) improve in a system test of OrcaMDF. dkavoiding-regressions-in-orcamdf-by-system-testing, the risk of bugs is constantly increasing, especially when I develop a large
Anatomy SQL Server article 6 avoid regressions http://improve.dk/avoiding-regressions-in-orcamdf-by-system-testing/ in a system test of OrcaMDF when I continue to add new features and support for new data structures to the OrcaMDF software, the risk of bugs is constantly increasing, especially when I develop a large
AnatomyArticle 6 of SQL Server
System
TestLi
AvoidRegressions)
Http://improve.dk/avoiding-regressions-in-orcamdf-by-system-testing/
When I continue to add new features and new data structures to support the OrcaMDF software, the risk of bugs increases.
Especially when I develop a large unknown function, I cannot predict the association between the structure and the structure. To reduce risks,TestIs necessary
UnitTest
UnitTestIs in Object-Oriented ProgrammingTestThe minimum part of a function in source codeTest. OneTestThe example is SqlBigInt data type parsing class,
He looks like this.
using System;using NUnit.Framework;using OrcaMDF.Core.Engine.SqlTypes;namespace OrcaMDF.Core.Tests.Engine.SqlTypes{ [TestFixture] public class SqlBigIntTests { [Test] public void GetValue() { var type = new SqlBigInt(); byte[] input; input = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F }; Assert.AreEqual(9223372036854775807, Convert.ToInt64(type.GetValue(input))); input = new byte[] { 0x82, 0x5A, 0x03, 0x1B, 0xD5, 0x3E, 0xCD, 0x71 }; Assert.AreEqual(8200279581513702018, Convert.ToInt64(type.GetValue(input))); input = new byte[] { 0x7F, 0xA5, 0xFC, 0xE4, 0x2A, 0xC1, 0x32, 0x8E }; Assert.AreEqual(-8200279581513702017, Convert.ToInt64(type.GetValue(input))); } [Test] public void Length() { var type = new SqlBigInt(); Assert.Throws(() => type.GetValue(new byte[9])); Assert.Throws(() => type.GetValue(new byte[7])); } }}
ThisTestContains the main entry point of the SqlBigInt class,TestWhether the long bigint data type causes overflow or underflow. It also includes the length check.
For simple type units such as SqlBigIntTestIt will work well. Sometimes UnitTestIt will be very complicated when the associated class needs to call the corresponding method, class, and other underlying structures supporting its running (mockTest)
Although this is a work strategy,TestThe entire architecture is dynamic, especially in the early stages of the project.
SystemTest
InTestIn terms of scope, we need a larger scope.Test-SystemTest.SystemTestDesignedTestSystemAs a whole, basically ignoreSystemInternal Working Principle
If you want to classify data, it can be divided into black boxes.Test. For OrcaMDF, I guess we can capture 90% of all regressions and only use 10% of the time,
Compared with the Starting UnitTestUse more time to capture only a small number of regressions.
Therefore, this is a good method during developmentTestAnd key units can be introduced.TestAnd integrationTest.
For exampleTestThe User table name resolution in the DatabaseMetaData class. I can simulate the Value List of SysObjects, and for the DatabaseMetaData class
The constructor can also simulate the parameters required by MdfFile. To do this, I must extract an interface from MdfFile and use mocking framework
SystemTestTo execute the following process:
1. Connect to the SQLSERVER instance
2.TestCreated in the firmware (Test fixture)TestArchitecture
3. Database Separation
4. Run OrcaMDF and load the separated database verification results
OneTestExample: create two user tables and verify the output of the DatabaseMetaData class.
using System.Data.SqlClient;using NUnit.Framework;using OrcaMDF.Core.Engine;namespace OrcaMDF.Core.Tests.Integration{ public class ParseUserTableNames : SqlServerSystemTest { [Test] public void ParseTableNames() { using(var mdf = new MdfFile(MdfPath)) { var metaData = mdf.GetMetaData(); Assert.AreEqual(2, metaData.UserTableNames.Length); Assert.AreEqual("MyTable", metaData.UserTableNames[0]); Assert.AreEqual("XYZ", metaData.UserTableNames[1]); } } protected override void RunSetupQueries(SqlConnection conn) { var cmd = new SqlCommand(@" CREATE TABLE MyTable (ID int); CREATE TABLE XYZ (ID int);", conn); cmd.ExecuteNonQuery(); } }}
In real life scenarios, this can be very fast.Test. ThinkTestResolution of forwarding records? You only need to create a newTest
Compile TSQL code to generate the status of the target database and then verify the table data scanned
SystemTestDisadvantages
UnfortunatelySystemTestIt is not a panacea, and it also has its shortcomings. The most obvious drawback is performance.
UnitTestIt usually needs to run very quickly, basically allowing you to run them in the background after each file is saved. From CPU binding to runningSystemTestIt takes half a second.
Fortunately, they can run in parallel. On a quad-core machine, I can run 480Test. This enables a completeTestSet control at reasonable time,
Keep at the same timeTestThe subset can run quickly. Normally, code changes are notTestToo many impacts
Article 6