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.
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.
Step 2 – Provide a name for the class as Tutorial.cs and click the Add button at the bottom of the screen.
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:
Step 6 − Add the Unit tests to the project. Right-click on Solution and choose the menu option 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.
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.
Step 9 – Next, go to Projects, choose Simple Reference and click OK.
Step 10 − Click Add Reference again, go to Assemblies and type Web in the Search box. Then add a reference of 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.
After running the test, it is observed that the Test successfully run on the left hand side of Visual Studio.
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.
Step 14 − Then go to Build Step → MS Build and click Add build step as depicted in the following screenshot.
Add the following values −
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.
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.
Now when the build is triggered, an initial output appears stating that the test is passed.
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.
Continuous Integration Related Interview Questions
|Testing Tools Interview Questions||Linux Interview Questions|
|Framework7 Interview Questions||Maven Interview Questions|
|Automation Testing Interview Questions||Jenkins Interview Questions|
|IBM Integration Bus Interview Questions||DevOps Interview Questions|
|Spring Batch Interview Questions|
All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.