This was 3rd years in a row, and on Saturday, September 15 I gave two sessions at Seattle Code Camp 2018

Session slides are available at my GitHub 

The first session was on “How to become a Software Architect”. Many aspirants and practicing architects attended my session and asked various questions on architect career path.

The second session was on “Microservices: what, why and how?”. This session also went very well, and I ran out of time to address all the questions related to many individual’s architecture designs and how to solve a problem they are facing. Hence, few topics were discussed after the session in the lobby.

What some of the participants said

I look forward to Seattle Code Camp 2019.

What is Live Unit Testing

Live Unit Testing is a brand-new technology, made available in Visual Studio 2017 version 15.3 or above. Live unit testing enables the IDE to execute unit tests automatically in real time without cod being built and as you make changes to the code.

Which frameworks and tooling support Live Unit Testing?

Live Unit Testing is available for C# and Visual Basic projects using MSTest, NUnit, or xUnit Test frameworks that target the .NET Core or .NET Framework in the Enterprise Edition of Visual Studio 2017.

Problem Statement

Unit Tests, and code have a very close relationship, and both depend heavily on each other. I.e. a change in source code must impact the unit test(s) code for what was being tested. Similarly, a change in a unit test, must impact the code coverage of the source code, which is being exercised via unit tests.

In the light of above mentioned problem statement, there is no efficient and developer friendly solution which a traditional unit tests can solve. Moreover, validating code changes through unit tests may quickly turn out to be a tedious task, as you must run all the unit tests from Test Explore after every code change.

Benefits of Live Unit Testing

It empower the developers to refactor and change their code with greater confidence. Live Unit Testing graphically depicts code coverage in real time and provides a quick visual view of the code coverage, and which code statements are passing in unit tests. As per the name “Live Unit Test”, you don’t have to build the code, and run the tests again via Test Explorer to validate the changes. I.e. soon after code changes are made, unit tests will be automatically executed to reflect the impact (pass, fail).

Quick look at a traditional Unit Test

As explained in my previous article Inside Out : TDD using C# there is always a system under test or code which needs to be exercised via unit tests. This code is available at my GitHub, and this code will work just fine for Unit Test, and Live Unit Test (if you have the required Visual Studio 2017) purposes.

The code below, shows unit tests written for Account.cs class’s IsAccountActive() function.

What is being tested?

As shown in the image above, Account.cs class’s IsAccountActive() method is being exercised. I.e. Account.cs is our System Under Test.

Let’s begin with Red, Refactor, Green

As this code is showcasing Test Driven Development, I.e. write a failing test, and then write code to make that test pass, and so on.

First, let’s write/refactor code to make TestAccountStatus_Active_Success() test case pass. To do so, copy the code from TestCase#1 code snippet from TextFile1.txt (included in the UnitTestBankApplication at my github

Account.cs code when TestAccountStatus_Active_Success() was failing:

Account.cs code changes to make TestAccountStatus_Active_Success() pass:

Now, if you will run the Tests again, by clicking “Run All” option in the Test Explorer, then you shall observe that 1/3 Test case is passing, as shown in the image below.

But what exactly is the problem here?

Unit Test code or source code which is being tested doesn’t explicitly tell which code lines are being covered, not covered, or passed via unit tests. I.e. whenever developer will change the code, test cases need to be run over and over to identify the impact, and that is without any visual clue in the code files. Hence, with traditional unit testing, a developer can’t clearly tell which code statements are covered, or not covered, through passed or failing unit tests.

Turn-on Live Unit Testing

Navigate to the Test menu, expand Live Unit Testing, and then click on Start, as shown in the image below.

If you don’t see this option then you might not have the appropriate version of Visual Studio 2017 Enterprise Edition, which offers the Live Unit Testing feature. However, if you have Visual Studio 2017 enterprise edition, and you don’t see this option, then you can add Live Unit Testing tool from the setup menu, and selecting it from the individual components tab.

Live Unit Testing in action

As soon as you have started the Live Unit Testing, your IDE will instantly start tracking the code changes in the background, as shown by X, , and symbols on the left of code statements in the IDE, as shown in the image below.

As of now, there is only one test passing, let’s take the Test Case#2 code from TestFile1.txt

and put it in Account.cs class’s IsAccountActive() function, and soon after putting the code in there, without building the code explicitly, you shall observe the changes, and notice that now two tests are passing. Alongside, you shall observe the changes to the code line symbols X, , and on the left.

Now, you may want to work on passing the third unit test, and to make that happen as per TDD guidelines, you code should refactor the code logic to accomplish that. Put the Test Case#3 code from TestFile1.txt, into Account.cs class’s IsAccountActive() function

As soon as the code is refactored, again without any explicit build and running tests from Test Explorer, Live Unit Testing observed the code changes and ran the tests. As shown in the image below, now all three unit tests are passing, and all code lines in Account.cs class’s IsAccountActive() shows symbol on their left. The  symbol means that all code statements in this function or block are covered by the Unit Tests.

Now, what’s next?

As you can see in the image above towards the bottom-half, ─ symbol in front of other code blocks, which means that these code blocks are covered by 0 test. I.e. no unit test case(s) exist for these code blocks. You may want to take it to next level by taking code from my GitHub repo, and expand it.

Pause or Stop Live Unit Testing

Once Live Unit Testing has been started, now it can be either paused or stopped. You can navigate to the Test menu, select Live Unit Testing, and then choose either Pause or Stop, as shown in the image below. Based on the choice you make; Live Unit Testing will be either paused or stopped completely.

Excluding individual Unit Tests from Live Unit Testing

Ideally, all the tests in all the projects will be covered once Live Unit Testing has been started.

But, you can use the following attributes to specify in the source code that you want to exclude targeted test methods from Live Unit Testing:

  • For MSTest: [TestCategory(“SkipWhenLiveUnitTesting”)]
  • For xUnit: [Trait(“Category”, “SkipWhenLiveUnitTesting”)]
  • For NUnit: [Category(“SkipWhenLiveUnitTesting”)]

Include/Exclude Unit Test Projects or Test class files

Live Unit Testing is IDE level, and it works for all test projects and all class files which are part of a test project. To include/exclude either a test project or a test class file, you can use the context menu and choose Live Unit Testing, Include or Exclude options. The image below shows these options on the UnitTestBankApplication Test Project, and you may want to try it on test class file as well.

Wrapping up

Live Unit Testing appears to be a milestone in fast-paced, technology-heavy software development field. This certainly doesn’t take away the importance of knowing Unit Test fundamentals, rather, it enforces the TDD (Test Driven Development) mindset in an effective, and productive manner to the developer community, by showing visual clues in the IDE code window, and running the tests while a developer is refactoring the code.

I THANK all my readers and followers in the tech community. My community contributions via www.C-SharpCorner.com reached 6 million read count.  https://www.c-sharpcorner.com/members/vidya-vrat-agarwal

Recap

C-sharpcorner Redmond chapter has been organizing a dinner event during the week of Microsoft MVP Summit. This year it was scheduled on March 6th 2018 for all the C-shaprcorner MVPs, invited Microsoft MVPs and few other guests.

67 C# Corner MVPs across the globe registered for this event https://www.c-sharpcorner.com/events/c-sharp-corner-mvp-dinner-microsoft-mvp-summit-2018 and many e-mailed me that they will attend.

This year, we had over 125 guests including some estemmed guests linke Scott Hanselmen (doesn’t require an introduction), Mads Torgerson (C# language PM at Microsoft), Kerry Herger (CPM Manager), and Joe Darko (CPM USA).

Moments

Moksha Indian Restaurant – Bellevue WA, USA

Moksha Indian Restaurant – Bellevue WA, USA

C# Corner and Microsoft MVPs with Scott Hanselman

Magnus, Mahesh, and Mads Torgerson (C# Language PM, Microsoft)

 

Objective

  • Setup git repository in VSTS
  • Build Continuous Integration (CI)/Continuous Deployment (CD) pipeline from scratch using VSTS
  • Enable CI
  • Create free web app service on Azure
  • Trigger CD after successful CI
  • End-to-end flow execution

Abstract

Continuous Integration (CI)/Continuous Deployment (CD) are widely used terms in the DevOps world. If you are new or don’t fully understand the buzzword DevOps then read my article DevOps, What, Why & How. Continuous Integration (CI) and Continuous Delivery(CD) enables and empowers any software delivery team in an organization to continuously deliver value to their end users.

Prerequisites

The application which you want to setup CI/CD pipeline for, that project code must be available in a code repository in VSTS (Visual Studio Team Services) read my article Beginning with git using VSTS can be helpful to set up a git repo from scratch using VSTS. Also, an Azure portal account is a must.

Creating a Build Definition

After successful Project and code setup in the git, you will see that your VSTS account will show code repository and a project like as shown below. Here, repository named TestProjects has an ASP.NET MVC application named WebApplication1.

Click on “Set up build” and begin with selecting a template “ASP.NET” as shown in the image below, click Apply. You may want to choose a template which is suitable for your application.

Setting the build tasks

If not already open then open the Tasks tab. By default, build definition name will be <ProjectName>-<BuildTemplateName>-CI (you can change this to something else if you wish to) and Agent queue will be empty, which needs to be set to Hosted (in case of .NET) or Hosted 2017 (in case of .NET Core)  as shown under Process blade in image below.

By default, build is being set up at the master branch on the project you initiated “set up build” from, which was TestProjetcs. You can verify this and change settings if needed using the “Get sources” blade as shown in the image below.

Build Template comes pre-configured with most of the tasks and hence you can review other tasks, but no changed would be required for successful execution from this step onwards (verified for MVC application), however, in your case, you may have to tweak some settings.

Queuing a CI build

To produce deployable artifacts, you need to submit a build of your code. To do so, click on Save & queue or if build definition is saved already then click on Queue which will ask for confirmation to kick-off a build as shown in the image below.

Click on Queue to initiate the process and you will notice that your screen will show that a Build #yyyymmdd.n have been queued.

To track the status of a build you can click on the build number link (as shown in the image above) and if everything was setup correctly then you will see “Build succeeded” as shown in the image below that all the build steps executed successfully.  To explore more about each build step, you can click on a step link shown in the left-pane of the window.

Exploring the Build Artifacts

CI build produces deployable artifacts and those can be seen via clicking on “Artifacts” link shown above Build details.

Setting up the Continuous Integration (CI)

Continuous Integration (CI) is when the code is being built on each check-in and that can be deployed to an environment. To set up this process, navigate to the build definition (click on Edit) and open the “Triggers” tab. By default, continuous integration is Disabled as shown in the image below.

Click on “Enable continuous integration” to enable the CI for TestProjetcs and it will include master branch as the default setting.

Click “Save” to keep the changes to the build definition.  Do not choose “Save and queue”

Continuous Integration (CI) in Action

Ensure that VSTS is open and you have Builds page open. Now switch to the Visual Studio and update the code of WebApplication1 under TestProjects repository

Click on “Commit All” to check-in the changes and push the code to master. Soon after that under the Builds in VSTS, you will notice that another build is kicked off and shows “in progress” status which was triggered by the commit “Title update in About.cshtml”.

After successful build process, you will see “succeeded” status

Setting up the Azure Web App

Before creating a Release definition, an environment needs to be set up for deployment. An azure web app is a perfect choice to host the MVC application.

Login to the azure portal and create a web app “WebApplication1-dev” for dev environment and so other flavors (qa, uat, staging, and production etc.) can be created as needed.

 

By default, the Web app is created as an S1 (small) pricing tier, but you can create your own service plan and select Free pricing tier. Refer to my article Free Web App Hosting on Azure

After successful Web app creation, it will be available at https://webapplication1-dev.azurewebsites.net/

Setting up the Continuous Delivery (CD)

Continuous Delivery (CD) is a software engineering approach in which teams produce deployable software which can be reliably released to an environment (dev, qa, uat, staging, and production) at any time.

To set up CD click on Build and Releases, then select Releases. Click on “New definition”.

A “New Release Definition” will be created with the template for release as shown in the image below. Change the name of the release to “TestProjects-ASP.NET-CD”, then click on Artifacts and select TestProjects-ASP.NET-CI.  Because, CI build artifacts will be deployed using Release dominion as CD process.

Next, it’s time to setup the Environment, rename it to dev and set values under “Tasks” tab as appropriate.

Creating a Release

After a Release definition has been set up, it’s time to deploy the CI build using the created release, this can be easily achieved by clicking on “Create release” link on the top-right corner.

“Create release” will summarize the setup of showing dev environment and created CI builds to choose from. By default, CI build will automatically kick off the release to the dev environment.

Select the latest build from the list of successful build versions and then click “Create” and notice that “Release-1” has been created.

Click on the link “Release-1” to check the status which will be shown as “IN PROGRESS”

After few seconds Deployment status will be updated to “SUCCEEDED”

Now, if you access the  https://webapplication1-dev.azurewebsites.net.WebApplication1-dev.azurewebsites.net then you will see that web application has been successfully deployed to Azure web app.

Setting up end-to-end automated CI/CD pipeline

In the Release definition click on Artifacts trigger icon (lightning symbol) and enable the continuous deployment trigger and select the branch.

Now, go to Visual Studio and make some changes to the About.cshtml and check-in the code to master branch of WebApplication1 project. Which will then kickoff a CI Build.

Successful CI build will then kick-off the Release for CD to the dev environment.

Upon successful execution of Release, the website will be deployed as shown below (see an updated message on the about.cshtml page).

This point onwards, whenever any code changes will be made using Visual Studio, then a CI build will spin and upon successful build execution, a Release (CD) will be created to deploy the web app.

Summary

CI/CD is the most widely used t the rm in industry today and helps in delivering continuous value delivery to the end users. VSTS and Azure offers a lot of great and powerful features to build CI/CD pipeline. This article has shown the process of building CI/CD pipeline from scratch and how to enable various triggers for CI/CD automation during this process.

Excellence

November 30th, 2017 | Posted by Vidya Vrat in Career Advice - (1 Comments)

“A person once visited a temple under construction where he saw a sculptor making an idol of God…Suddenly he noticed a similar idol lying nearby…Surprised, he asked the sculptor, “Do you need two statues of the same idol?” “No,” said the sculptor without looking up, “We need only one, but the first one got damaged at the last stage…”.

The gentleman examined the idol and found no apparent damage… “Where is the damage?” he asked. “There is a scratch on the nose of the idol.” said the sculptor, still busy with his work…. “Where are you going to install the idol?” The sculptor replied that it would be installed on a pillar twenty feet high… “If the idol is that far who is going to know that there is a scratch on the nose?” the gentleman asked. The sculptor stopped work, looked up at the gentleman, smiled and said, “I will know it…

” The desire to excel is exclusive of the fact whether someone else appreciates it or not…. “Excellence” is a drive from inside, not outside…. Excellence is not for someone else to notice but for your own satisfaction and efficiency. Don’t Climb a Mountain with an Intention that the World Should See You, Climb the Mountain with the Intention to See the World.

I have done an official Technical Review of a packtpub video course “Learning Object Oriented Programming with C# 7”.
https://www.packtpub.com/application-development/learning-object-oriented-programming-c-7-video

This video has total 7 modules and available for purchase via www.packypub.com.

Learning Object Oriented Programming with C# 7 [Video] Book Cover

 

I spoke at Silicon Valley Code Camp 2017 in San Jose, CA on Oct 7th 2017 and my topic was Need of DevOps in the Enterprise.

• Need of DevOps in the Enterprise https://lnkd.in/eQf3dFm

It was nice experience to speak in Silicon Valley and meet college students to very well experienced professionals. I was really honored to have Ron Lichty attend my session and at the end mentioning that it was a great session.

Microsoft MVP team was also there to sponsor and socialize about all the MVP Speakers at Silicon Valley Code Camp (SVCC) 2017.

Slide of my session can be found at my Github

Overall it was nice experience, I also met some Microsoft Evangelists and fellow C# Corner and Microsoft MVPs.

I want to THANK all my readers in the .NET community. Today I have reached 5 million read count at www.C-Sharpcorner.com

My C-Sharpcorner profile – http://www.c-sharpcorner.com/members/vidya-vrat-agarwal

 

 

Seattle Code Camp 2017

I spoke at Seattle Code Camp 2017 on 09/09/2017 and covered two topics.

• AntiPatterns Every Software Development Team Must Know https://lnkd.in/ebEMDBb
• DevOps: What, why and how?
https://lnkd.in/eQf3dFm

Seattle Code Camp started with a Keynote from Microsoft’s Jeremy Foster and he shared a slide with all Microsoft MVP (Most Valuable Professionals) and FTE (Full Time Employee) who were speaking at 09/09/2017 Seattle Code Camp.

Microsoft got separate printed agenda for MVP and FTE Sessions

Session Details

My 1st Session on AntiPattern was in Room#103 at 11 am -12 pm. I had a brief introduction and begin with the presentation. As already set the expectation with the audience, I kept it very interactive and many participated well to share knowledge and experiences with others.

Some of the attendees even spoke to their friends in the lunch break and recommended them to attend my next session. Some of the attendees returned for the 2nd session for DevOps at 1-2pm and some mentioned that it was the best talk they attended. Well, I thank them for their kind words and patience to provide me an opportunity to share my thoughts with them.

What people said after my sessions

Presentation Slides

Slides are available at https://github.com/vidyavrat/SeattleCodeCamp2017

Contact Me

Please connect with my via
LinkedIn : https://www.linkedin.com/in/vidyavrat/
Twiter : https://twitter.com/dotnetauthor

Send me a message using Contact Me tab on the blog.