SlideServe
Menu
Préférences
© SlideServe · v2026

Enhancing Database Development with xUnit Testing: Insights from Chris Oldwood

sef avatar
21 diapositives · 360 Views · Sep 09, 2014

This presentation by Chris Oldwood, delivered on January 20, 2011, at ACCU in London, focuses on effective database development processes using the xUnit testing model. It emphasizes Test-First Development, Continuous Integration, and the importance of automated testing with real datasets. Key topics include isolation in testing, the use of scaffolding for automation, and practical examples of NUnit testing frameworks. Oldwood explores the implications of referential integrity and best practices for deploying SQL scripts, thereby guiding developers toward a more efficient and reliable database environment.

Enhancing Database Development with xUnit Testing: Insights from Chris Oldwood - slide 1
01 / 21Enhancing Database Development with xUnit Testing: Insights from Chris Oldwood
1 / 17

Télécharger la présentation

Enhancing Database Development with xUnit Testing: Insights from Chris Oldwood
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. xUnit Style Database Unit Testing ACCU London – 20th January 2011 Chris Oldwood gort@cix.co.uk

  2. Presentation Outline • Database Development Process • The xUnit Testing Model • Test First Development • Continuous Integration/Toolchain • Pub

  3. Legacy Database Development • Shared development environment • Only integration/system/stress tests • No automated testing • Only real data not test data • Referential Integrity – all or nothing • No automated build & deployment

  4. Ideal Development Process • Isolation • Scaffolding • Automation

  5. Example Testable Behaviours • Default constraint • Trigger to cascade a delete • Refactoring to a surrogate key

  6. NUnit Test Model [TestFixture] public class ThingTests { [Test] public void Thing_DoesStuff_WhenAskedTo() { var input = ...; var expected = ...; var result = ...; Assert.That(result, Is.EqualTo(expected)); } }

  7. NUnit Test Runner • Tests packaged into assemblies • Uses reflection to locate tests • In-memory to minimise residual effects • Output to UI/console

  8. SQL Test Model create procedure test.Thing_DoesStuff_WhenAskedTo as declare @input varchar(100) set @input = ... declare @expected varchar(100) set @expected = ... declare @result varchar(100) select @result = ... exec test.AssertEqualString @expected, @result go

  9. SQL Test Runner • Tests packaged into scripts (batches) • Uses system tables to locate tests • Uses transactions to minimise residual effects • Output to UI/console

  10. SQL Asserts • Value comparisons (string, datetime, …) • Table/result set row count • Table/result set contents • Error handling (constraint violations)

  11. Setup & Teardown • Per-Fixture (static data) • Per-Test (specific data) • Use helper procedures

  12. Default Constraint Test create procedure test.AddingTask_SetsSubmitTime as declare @taskid int declare @submitTime datetime set @taskid = 1 insert into Task values(@taskid, ...) select @submitTime = t.SubmitTime from Task t where t.TaskId = @taskid exec test.AssertDateTimeNotNull @submitTime go

  13. Trigger Test create procedure DeletingUser_DeletesUserSettings as ... set @userid = 1 insert into AppUser values(@userid, ...) insert into AppUserSettings values(@userid, ...) delete from AppUser where UserId = @userid select @rows = count(*) from AppUserSettings where UserId = @userid exec test.AssertRowCountEqual @rows, 0 go

  14. Unique Key Test create procedure AddingDuplicateCustomer_RaisesError as ... insert into Customer values(‘duplicate’, ...) begin try insert into Customer values(‘duplicate’, ...) end try begin catch set @threw = 1 end catch exec test.ErrorRaised @threw go

  15. Automation • Enables easy regression testing • Enables Continuous Integration • Performance can be variable

  16. Test First Development • Start with a requirement • Write a failing test • Write production code • Test via the public interface

  17. The Public Interface • Stored procedures • Views • Tables?

  18. Implementation Details • Primary keys • Foreign keys • Indexes • Triggers • Check constraints • Default constraints

  19. Deployment Testing Build version N then patch to N+1 then run unit tests Build version N+1 then run unit tests ==

  20. Buy or Build? • Batch file, SQL scripts & SQLCMD • TSQLUnit & PL/Unit • Visual Studio • SQL Server/Oracle Express

  21. “The Oldwood Thing”http://chrisoldwood.blogspot.com Chris Oldwood gort@cix.co.uk