SlideShare a Scribd company logo
EFFECTIVE .NET CORE UNIT TESTING
WITH SQLITE AND DAPPER
Mike Melusky – Philly.NET
November 17, 2018
ABOUT SPEAKER
• Michael Melusky
• Software Developer for Audacious Inquiry in Baltimore, MD
• Adjunct Instructor at Penn State University
TOPICS
• Motivation for this talk
• Apply testing to a “real world” . Netcore C# example
• Closing thoughts
CODE FOR TODAY
• I have a starter project available on Github:
• https://github.com/mrjavascript/phillynet-codecamp-2018-2
• All code for today will be pushed to this repository
• Slides on SlideShare (mrjavascript)
WHY UNIT TESTING?
STACK OVERFLOW DEVELOPER SURVEY
• Each year Stack Overflow polls developers, asking questions to gauge
popular languages and frameworks and technologies
• Jetbrains (the company behind IntelliJ and Resharper) started publishing
their own survey as well
• There was an alarming survey response to a question regarding unit
testing in the Jetbrains survey
Effective .NET Core Unit Testing with SQLite and Dapper
WHAT IS UNIT TESTING?
• Testing individual units of code
• Numerous frameworks are available for this:
• Java:
• jUnit / Mockito
• .NET:
• xUnit, nUnit, mstest, Moq
• Javascript:
• Jest, Cucumber, Mocha, Enzyme, Protractor … (many, many, many, many
more)
JAVA MAKES
IT EASY!
• Spring Framework
recommends having two
separate source trees, one
for “main” and one for
“test”
• No excuse to not do unit
testing
WHAT ABOUT .NET?
• About me, I’m a “Java Developer” by trade
• Code is written in Java 8 with Spring Boot 2
• Production Database is PostGreSQL 10
• Uses jUnit and Mockito for testing frameworks
BUILDING A RESTFUL API
• For building a RESTful API or backend application, generally the
application is layered into the following components:
• Controller – handles HTTP request and responses from the clients
• Service – applies transactional business logic and validation
• Repository – data access layer (SQL or ORM like Hibernate or Entity
Framework)
JAVA UNIT TESTS
• As mentioned, the live data exists in a production PostGreSQL database.
• For the unit tests, the same code is ran against a different in memory
database (in this case H2)
• I recently had to build a .NET Core 2 application which connects to
Microsoft SQL Server
• I wanted to apply the same testing strategies used with .NET (data
access layer code queries SQL Server in production, but uses a in
memory database for tests)
XYZ WIDGET CORPORATION
XYZ WIDGET CORPORATION
• Assume we recently were hired to work for XYZ Widget Corporation
• Our first task as an employee is to find a way to integrate unit testing
into a new .NET Core application another developer wrote
• ** DEMO **
.NET UNIT TESTING FRAMEWORKS
• The following options are available for writing unit tests with .NET Core
• Nunit
• MsBuild
• Xunit
• I’m using Xunit for these examples (personal preference)
N U N I T
E X A M P L E
LETS INTEGRATE XUNIT INTO CODE
• Before we do this, we need an in-memory database to run the unit tests
against
• For these examples, let’s use SQLite
• ** DEMO **
UNIT TESTING BEST PRACTICES
TEST DRIVEN
DEVELOPMENT
• A paradigm where the unit
tests are written before the
application code
• .NET Core makes this easy!
• This might be a utopia for
some applications however…
BEST PRACTICES
• Run code coverage reports!
• Make unit tests quick so developers get into the habit of running tests
before pushing code
• If you receive a JIRA ticket for a bug fix, write unit tests to verify your
changes!
• ** DEMO CODE COVERAGE **
EXAMPLE TEST CASE – 3RD PARTY API
REFERENCES
• Stack Overflow Developer Survey 2018 -
https://insights.stackoverflow.com/survey/2018/
• Jetbrains Developer Survey -
https://www.jetbrains.com/research/devecosystem-2018/
• SQLite & SQL Server Compact Toolbox extension for Visual Studio -
https://github.com/ErikEJ/SqlCeToolbox
THANK YOU FOR COMING!
• @mrjavascript on Twitter/GitHub/SlideShare…

More Related Content

What's hot (20)

PDF
Clean Architecture in Android. UPTech TechTalk
Halyna Halkina
 
PPTX
Xp conf-tbd
XP Conference India
 
PDF
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
Xebia Nederland BV
 
PDF
Acceptance Test Drive Development with Robot Framework
Ramdhan Hidayat
 
PDF
RoboCon 2018: How did we get here? Where do we go next?
Pekka Klärck
 
PDF
Barcamp Bangkhen :: Robot Framework
Somkiat Puisungnoen
 
PDF
Luis Correia - Instituto de Informática - OSL19
marketingsyone
 
PDF
Functional Tests Automation with Robot Framework
laurent bristiel
 
PDF
Robot Framework with actual robot
Eficode
 
PPT
Introduction to Eclipse IDE
Muhammad Hafiz Hasan
 
PPTX
Testing Without a GUI Using TestComplete
SmartBear
 
PDF
Click, Click, Test - Automated Tests for APEX Applications
Kai Donato
 
PDF
deliver:agile - Enable your Agile Team with Continuous Delivery Pipelines
Esteban Garcia
 
PDF
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
PDF
Mozilla: Mozmill meets L10n
Henrik Skupin
 
PPT
Unit testing using Mock objects and dependency injection
Yn Reddy
 
PDF
Robot Framework Introduction & Sauce Labs Integration
Sauce Labs
 
PDF
Android clean architecture workshop 3h edition
Jorge Ortiz
 
PDF
NSTC2019: Choosing CI Friendly Mobile Automation Framework
Shashikant Jagtap
 
Clean Architecture in Android. UPTech TechTalk
Halyna Halkina
 
Xp conf-tbd
XP Conference India
 
TestWorks Conf Robot framework - the unsung hero of test automation - Michael...
Xebia Nederland BV
 
Acceptance Test Drive Development with Robot Framework
Ramdhan Hidayat
 
RoboCon 2018: How did we get here? Where do we go next?
Pekka Klärck
 
Barcamp Bangkhen :: Robot Framework
Somkiat Puisungnoen
 
Luis Correia - Instituto de Informática - OSL19
marketingsyone
 
Functional Tests Automation with Robot Framework
laurent bristiel
 
Robot Framework with actual robot
Eficode
 
Introduction to Eclipse IDE
Muhammad Hafiz Hasan
 
Testing Without a GUI Using TestComplete
SmartBear
 
Click, Click, Test - Automated Tests for APEX Applications
Kai Donato
 
deliver:agile - Enable your Agile Team with Continuous Delivery Pipelines
Esteban Garcia
 
A Separation of Concerns: Clean Architecture on Android
Outware Mobile
 
Mozilla: Mozmill meets L10n
Henrik Skupin
 
Unit testing using Mock objects and dependency injection
Yn Reddy
 
Robot Framework Introduction & Sauce Labs Integration
Sauce Labs
 
Android clean architecture workshop 3h edition
Jorge Ortiz
 
NSTC2019: Choosing CI Friendly Mobile Automation Framework
Shashikant Jagtap
 

Similar to Effective .NET Core Unit Testing with SQLite and Dapper (20)

PPTX
Skillwise Unit Testing
Skillwise Group
 
PPTX
Binary Studio Academy: .NET Code Testing
Binary Studio
 
PPTX
NET Code Testing
Kirill Miroshnichenko
 
PPTX
RIA 06 & 07 - Unit Testing in Detail
Johannes Hoppe
 
PPTX
Coding Naked
Caleb Jenkins
 
PPTX
Implementing TDD in for .net Core applications
Ahmad Kazemi
 
KEY
Driving application development through behavior driven development
Einar Ingebrigtsen
 
PPTX
Unit testing
PiXeL16
 
PPTX
Unit testing
Panos Pnevmatikatos
 
PDF
(automatic) Testing: from business to university and back
David Rodenas
 
PPTX
Coding Naked 2023
Caleb Jenkins
 
PPTX
Techorama 2017 - Testing the unit, and beyond.
Bert Brouns
 
PPTX
Modern ASP.NET Webskills
Caleb Jenkins
 
PPTX
Unit Testing and TDD 2017
Xavi Hidalgo
 
PPTX
The Test way
Mikhail Grinfeld
 
PPTX
Unit Testing talk
Sergei Kukharev
 
PPTX
Unit Testing in Java
Ahmed M. Gomaa
 
PPT
Using xUnit as a Swiss-Aarmy Testing Toolkit
Chris Oldwood
 
PPTX
Testing 101
Noam Barkai
 
PPTX
8-testing.pptx
ssuserd0fdaa
 
Skillwise Unit Testing
Skillwise Group
 
Binary Studio Academy: .NET Code Testing
Binary Studio
 
NET Code Testing
Kirill Miroshnichenko
 
RIA 06 & 07 - Unit Testing in Detail
Johannes Hoppe
 
Coding Naked
Caleb Jenkins
 
Implementing TDD in for .net Core applications
Ahmad Kazemi
 
Driving application development through behavior driven development
Einar Ingebrigtsen
 
Unit testing
PiXeL16
 
Unit testing
Panos Pnevmatikatos
 
(automatic) Testing: from business to university and back
David Rodenas
 
Coding Naked 2023
Caleb Jenkins
 
Techorama 2017 - Testing the unit, and beyond.
Bert Brouns
 
Modern ASP.NET Webskills
Caleb Jenkins
 
Unit Testing and TDD 2017
Xavi Hidalgo
 
The Test way
Mikhail Grinfeld
 
Unit Testing talk
Sergei Kukharev
 
Unit Testing in Java
Ahmed M. Gomaa
 
Using xUnit as a Swiss-Aarmy Testing Toolkit
Chris Oldwood
 
Testing 101
Noam Barkai
 
8-testing.pptx
ssuserd0fdaa
 
Ad

More from Mike Melusky (20)

PPTX
Container Orchestration for .NET Developers
Mike Melusky
 
PPTX
Containerize all the things!
Mike Melusky
 
PPTX
Building a Google Cloud Firestore API with dotnet core
Mike Melusky
 
PPTX
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
PPTX
Reactive Web Development with Spring Boot 2
Mike Melusky
 
PPTX
Building xamarin.forms apps with prism and mvvm
Mike Melusky
 
PPTX
Introduction to react native with redux
Mike Melusky
 
PPTX
Xamarin.Forms Bootcamp
Mike Melusky
 
PPTX
An evening with React Native
Mike Melusky
 
PPTX
Progressive Web Apps and React
Mike Melusky
 
PPTX
Into to Docker (Central PA Java User Group - 8/14/2017)
Mike Melusky
 
PPTX
An afternoon with angular 2
Mike Melusky
 
PPTX
An evening with Angular 2
Mike Melusky
 
PPTX
Securing your azure web app with asp.net core data protection
Mike Melusky
 
PPTX
Ember.js and .NET Integration
Mike Melusky
 
PPTX
Building Native “apps” with Visual Studio 2015
Mike Melusky
 
PPTX
Emberjs and ASP.NET
Mike Melusky
 
PPTX
Fun with lambda expressions
Mike Melusky
 
PPTX
An evening with querydsl
Mike Melusky
 
PPTX
Fun with lambda expressions
Mike Melusky
 
Container Orchestration for .NET Developers
Mike Melusky
 
Containerize all the things!
Mike Melusky
 
Building a Google Cloud Firestore API with dotnet core
Mike Melusky
 
Effective .NET Core Unit Testing with SQLite and Dapper
Mike Melusky
 
Reactive Web Development with Spring Boot 2
Mike Melusky
 
Building xamarin.forms apps with prism and mvvm
Mike Melusky
 
Introduction to react native with redux
Mike Melusky
 
Xamarin.Forms Bootcamp
Mike Melusky
 
An evening with React Native
Mike Melusky
 
Progressive Web Apps and React
Mike Melusky
 
Into to Docker (Central PA Java User Group - 8/14/2017)
Mike Melusky
 
An afternoon with angular 2
Mike Melusky
 
An evening with Angular 2
Mike Melusky
 
Securing your azure web app with asp.net core data protection
Mike Melusky
 
Ember.js and .NET Integration
Mike Melusky
 
Building Native “apps” with Visual Studio 2015
Mike Melusky
 
Emberjs and ASP.NET
Mike Melusky
 
Fun with lambda expressions
Mike Melusky
 
An evening with querydsl
Mike Melusky
 
Fun with lambda expressions
Mike Melusky
 
Ad

Recently uploaded (20)

PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
DevBcn - Building 10x Organizations Using Modern Productivity Metrics
Justin Reock
 
Biography of Daniel Podor.pdf
Daniel Podor
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
July Patch Tuesday
Ivanti
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
IoT-Powered Industrial Transformation – Smart Manufacturing to Connected Heal...
Rejig Digital
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 

Effective .NET Core Unit Testing with SQLite and Dapper

  • 1. EFFECTIVE .NET CORE UNIT TESTING WITH SQLITE AND DAPPER Mike Melusky – Philly.NET November 17, 2018
  • 2. ABOUT SPEAKER • Michael Melusky • Software Developer for Audacious Inquiry in Baltimore, MD • Adjunct Instructor at Penn State University
  • 3. TOPICS • Motivation for this talk • Apply testing to a “real world” . Netcore C# example • Closing thoughts
  • 4. CODE FOR TODAY • I have a starter project available on Github: • https://github.com/mrjavascript/phillynet-codecamp-2018-2 • All code for today will be pushed to this repository • Slides on SlideShare (mrjavascript)
  • 6. STACK OVERFLOW DEVELOPER SURVEY • Each year Stack Overflow polls developers, asking questions to gauge popular languages and frameworks and technologies • Jetbrains (the company behind IntelliJ and Resharper) started publishing their own survey as well • There was an alarming survey response to a question regarding unit testing in the Jetbrains survey
  • 8. WHAT IS UNIT TESTING? • Testing individual units of code • Numerous frameworks are available for this: • Java: • jUnit / Mockito • .NET: • xUnit, nUnit, mstest, Moq • Javascript: • Jest, Cucumber, Mocha, Enzyme, Protractor … (many, many, many, many more)
  • 9. JAVA MAKES IT EASY! • Spring Framework recommends having two separate source trees, one for “main” and one for “test” • No excuse to not do unit testing
  • 10. WHAT ABOUT .NET? • About me, I’m a “Java Developer” by trade • Code is written in Java 8 with Spring Boot 2 • Production Database is PostGreSQL 10 • Uses jUnit and Mockito for testing frameworks
  • 11. BUILDING A RESTFUL API • For building a RESTful API or backend application, generally the application is layered into the following components: • Controller – handles HTTP request and responses from the clients • Service – applies transactional business logic and validation • Repository – data access layer (SQL or ORM like Hibernate or Entity Framework)
  • 12. JAVA UNIT TESTS • As mentioned, the live data exists in a production PostGreSQL database. • For the unit tests, the same code is ran against a different in memory database (in this case H2) • I recently had to build a .NET Core 2 application which connects to Microsoft SQL Server • I wanted to apply the same testing strategies used with .NET (data access layer code queries SQL Server in production, but uses a in memory database for tests)
  • 14. XYZ WIDGET CORPORATION • Assume we recently were hired to work for XYZ Widget Corporation • Our first task as an employee is to find a way to integrate unit testing into a new .NET Core application another developer wrote • ** DEMO **
  • 15. .NET UNIT TESTING FRAMEWORKS • The following options are available for writing unit tests with .NET Core • Nunit • MsBuild • Xunit • I’m using Xunit for these examples (personal preference)
  • 16. N U N I T E X A M P L E
  • 17. LETS INTEGRATE XUNIT INTO CODE • Before we do this, we need an in-memory database to run the unit tests against • For these examples, let’s use SQLite • ** DEMO **
  • 18. UNIT TESTING BEST PRACTICES
  • 19. TEST DRIVEN DEVELOPMENT • A paradigm where the unit tests are written before the application code • .NET Core makes this easy! • This might be a utopia for some applications however…
  • 20. BEST PRACTICES • Run code coverage reports! • Make unit tests quick so developers get into the habit of running tests before pushing code • If you receive a JIRA ticket for a bug fix, write unit tests to verify your changes! • ** DEMO CODE COVERAGE **
  • 21. EXAMPLE TEST CASE – 3RD PARTY API
  • 22. REFERENCES • Stack Overflow Developer Survey 2018 - https://insights.stackoverflow.com/survey/2018/ • Jetbrains Developer Survey - https://www.jetbrains.com/research/devecosystem-2018/ • SQLite & SQL Server Compact Toolbox extension for Visual Studio - https://github.com/ErikEJ/SqlCeToolbox
  • 23. THANK YOU FOR COMING! • @mrjavascript on Twitter/GitHub/SlideShare…