Continuous Integration Testing - Continuous Integration

What is Continuous Integration Testing?

The feature of the Continuous Integration is that the -going testing should hold all the code built by the CI server. After the CI carries out a build, ensure that the test codes are in place to receive the code tested. As a part of CI Suite, every CI server can run the unit tests. In .Net, the feature of testing is inbuilt in .Net framework and the same is incorporated in CI server.

How to define a Continuous Integration test case in .Net?

To define a test case in .Net, a unit test needs to be defined for the sample project. This is done with the following steps:

Step 1 – A new case is added to the solution, which is used in the unit test. The class holds the string “Continuous Integration”, which is displayed in the web page. Right-click on the Simple Project and choose the menu option Add → Class.

Add Class

Step 2 – Provide a name for the class as Tutorial.cs and click the Add button at the bottom of the screen.

Tutorial CS

Step 3 − Open the Tutorial.cs file and add the following code in it. By this code, a string Name is created and the name is assigned to a string value as Continuous Integration, in the Constructor.

Step 4 − Change are made to Demo.aspx.cs file to use this new class.The code is updated in the file with the following code. A new instance of the class created above is created by the code.

Step 5 − In the demo.aspx file, refer the tp.Name variable, which was created in the aspx.cs file.

Run the code in Visual Studio to ensure the working of the code with the changes. On completion of the compilation, the output should appear as follows:

Continuous Integration Output

Step 6 − Add the Unit tests to the project. Right-click on Solution and choose the menu option Add → New Project.

Add New Project

Step 7 − Navigate to Test and on the right hand side, choose Unit Test Project. Give a name as DemoTest and then click OK.

Unit Test Project

Step 8 − In the Demo Test project, add a reference to the Simple project and to the necessary testing assemblies. Right-click on the project and choose the menu option Add Reference.

Add Reference

Step 9 – Next, go to Projects, choose Simple Reference and click OK.

Simple Reference

Step 10 − Click Add Reference again, go to Assemblies and type Web in the Search box. Then add a reference of System.Web.

System Web

Step 11 − In the Unit Test file, add the following code. The code ensures that the class has a string name variable. The simple test case is as:

Step 12 – Run the test in Visual Studio to make sure it works. In Visual Studio, choose the menu option Test → Run → All Tests.

Test Run All Tests

After running the test, it is observed that the Test successfully run on the left hand side of Visual Studio.

Test Successful

How to enable Continuous Testing within TeamCity?

As all the test cases are in place, these test cases are integrated into the TeamCity server by the following steps:

Step 13 − Create a build step in our Project configuration. In project home click Edit Configuration Settings.

Edit Configuration Settings

Step 14 − Then go to Build Step → MS Build and click Add build step as depicted in the following screenshot.

Build Step MSBuild

Add the following values −

  • Choose the runner type as Visual Studio Tests.
  • Enter an optional Test step name.
  • Choose the Test Engine type as VSTest.
  • Choose the Test Engine version as VSTest2013.
  • In the Test files name, provide the location as DemoTest\Bin\Debug\DemoTest.dll – DemoTest is the project name containing the Unit Tests. The DemoTest.dll will be generated by our first build step.
  • Click on Save

New Build Step

Now 2 build steps are there for the project. The first build step builds the application code and the test project. The second build step is to run the test cases.

Build Steps

Step 15 − Now check-in all code in Git, so that the entire build process can be triggered. run the git add and git commit command from the Demo parent folder as shown in the following screenshot.

Demo Parent Folder

Now when the build is triggered, an initial output appears stating that the test is passed.

Initial Output

Step 16 − Click on the Test passed result and go to the Test tab, it is observed that the UnitTest1 was executed and is passed.

Unit Test 1

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd Protection Status

Continuous Integration Topics