Skip to content

muqadar-ali/svt-continuous-integration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

svt-continuous-integration

Configure SQL Test, Visual Studio NUnit Tests, TFS, and TeamCity (Continuous Integration)

Getting Started

This readme will guide you through installation and configuration of SQL Test, TeamCity, TFS, and Visual Studio NUnit from scratch.

Prerequisites

  • Visual Studio installed
  • SQL server installed
  • Have a hotmail/live/outlook email id
  • Sign in to visual studio with account

Download Setups

alt text

Installing

TeamCity

Run downloaded setup of teamcity and proceed with standard installation. It will prompt for a port in during installation.
Enter port i.e. 8888 and note that down. After a few steps of installtion, it will show an information
window
like this

alt text

Next step is to select system account for given steps like this

alt text

Once you are done with installtion, it will automatically start teamcity in your default browser. Follow below given steps if it doesn't start.

  1. Open cmd as admin.
  2. Enter
cd C:\TeamCity\bin
  1. execute command
teamcity-server start
  1. Open localhost:yourport in browser. you will have to go through a few steps more in browser if it is the first time that you have installed teamcity on your machine. follow those steps i.e. create account (enter username, password). One of those steps will be about Database. Have a look at given image and select that option and go on with further steps if any.

Image Source: https://confluence.jetbrains.com/display/TCD10/Installation+Quick+Start

alt text

Setup is done.

tSQLt Runner

Open teamcity in browser, go to Administration tab on top

alt text

Scroll down and click Plugins List

alt text

follow below shown steps

alt text

select zip and click upload

alt text

Now you should see tsqlt runner in external plugins

alt text

SQL Test

Run downloaded sql test setup and select only SQL Test

alt text

and go on with standard installation

Verify sql test installation
  1. Open Microsoft SQL Server Management Studio (MSSMS) and connect with your username and password.
  2. Go to Databases and right click on any schema/database.
  3. You should see following options

alt text

Running sql test in Microsoft SQL Server Management Studio (MSSMS)

Open MSSMS Go to Databases Right click on any schema/database Click New Test and after that you should see below given option if it is the first time.

alt text

Write test case name(test stored procedure)

  • It should start with test word (standard notation)

alt text

After above steps, you should see an auto generated new sample test case like this

alt text

Inorder to keep this tutorial simple, remove comments and make a small change in above shown test case i.e. it should look like this

alt text

Execute this test case (procedure script)

alt text

You should see below given message

alt text

After that, go to below shown tab

alt text

Run test case in MSSMS to verify if framework works or not

alt text

Success message

alt text

Configure and run

Create TFS project live (Tested using hotmail account)

Go to TFS Online: https://visualstudio.microsoft.com/vso/
Get started for free
Sign in (Sign up and sign in if you do not have microsoft account i.e. hotmail/live/outlook)
Create project as shown below

alt text

then

alt text

And you should see your first TFS project created

alt text

Now we need to generate token. To do that, go to security tab as shown below

alt text

Click add as shown below

alt text

fill the given fields

alt text

scroll down and click Create Token

alt text

you should now copy the generated token and note it down as shown below

alt text

you have successfully configured tfs online. Now it is time to create a visual studio project with NUnit tests.

Create visual studio project

Go to File => New => Project and select the project as shown below. Name the project same as you named the tfs repository (in order to keep it simple for now)

alt text

now you have empty test method as shown below but it is in MSTest framework. (We will change it to NUnit as we move further)

alt text

Add a new project to same solution (that needs to be nested)

alt text

select project type as shown below

alt text

now you have empty class

alt text

change above shown class to calculator class (for testing purpose)

alt text

Adding reference of calculator project (ClassLibrary1) to testing project

alt text

select as shown below

alt text

Adding NUnit test framework and NUnit adapter to the test project

alt text

alt text

alt text

alt text

Change UnitTest1 class (or whatever you named it) as shown below

alt text

Build solution
Run test cases as shown below

alt text

Go to Test Explorer to see results

alt text

Test cases result

alt text

you can also run tests using Test Explorer

alt text

connect remote repository (online tfs) to visual studio project

Open team explorer

alt text

Click connect

alt text

alt text

select the project

alt text

map and get project

alt text

mapped successfully. now we need to push the project (add to source control)

alt text

alt text

alt text

go to team explorer => pending changes => check in changes

alt text

alt text

alt text

alt text

tfs is configured. follow next step of creating project in teamcity

Creating project in teamcity

Open team city in browser and click Administration tab on top before we move on to creating project, let's add some tools.

alt text

alt text

add NUnit console

alt text

select NUnit console version

alt text

again click install tool and add NuGet installer (version 4.8.1 for this tutorial)

alt text

Go to Administration tab and then create new project

alt text

after that, select visual studio team service

alt text

alt text

choose repository

alt text

and after that you will be prompted with an option, just click Proceed.

alt text

after this, just click cancel and go to Parameters tab.
we need to add 4 parameters.

alt text

alt text

add project name parameter

alt text

click add parameter as shown in one of above pics.
this time, add database server parameter. you can find your database server name by clicking
Microsoft sql server management studio

alt text

alt text

click add parameter and add database name.
you can get your database name from microsoft sql server management studio as shown below

alt text

alt text

click add parameter and add database username

alt text

parameters added. you should see these 4 parameters

alt text

Now we need to add 4 build steps. Go to build steps tab

alt text

alt text

select NuGet installer

alt text

add NuGet installer to your project and save

alt text

click add build step and select MS Build
add MS Build step

alt text

save.

click add build step and select NUnit add NUnit step

alt text

save

click add build step and select tSQLt Runner
add tSQLt Runner step (to run sql tests)

alt text

you should see these 4 build steps

alt text

In order to avoid any errors, go to visual studio project and make some kind of changes to project like go to calculator class go to add method change return statement from

return a+b; 

to

return a+b+3;

save it (Ctrl+S) and again change it to

return a+b;

save it (Ctrl+S). Go to team explorer => pending changes => check in

alt text

THE TIME HAS COME !

A few steps more to run teamcity continuous integration

Redirect to: localhost:yourport in your browser and click your project

alt text

click run and wait for the result

alt text

result

alt text

You have your continuous integration. Enjoy!.

Common Errors

  • NuGet missing on computer

alt text

  • Solutions

Case 1.

Add NuGet installer in your teamcity build step on top (1st step).

Case 2.

Go to your visual studio project.

Change a few lines.

Save it.

Again undo changes.

Save it.

Go to team explorer => pending changes => check in.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published