Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Creating NUnit Test Project
WhatsApp
Kaushik S
9y
40.5k
0
0
100
Article
NunitTestProject.zip
Create a class library.
Manage Nuget package and install:
NUnit
NUnit Test Adapter for vs2012, vs2013 and vs2015
The reference should be added to class library,
Create a console project in the same solution and add the reference of the project to the class library.
In the unit test project add the below code to test the console project.
[TestFixture]
public
class
UnitTest1 {
DecimalToBinary obj =
null
;
Fibonacci fObj =
null
;
FizzBizz fbObj =
null
;
public
UnitTest1()
{
obj =
new
DecimalToBinary();
fObj =
new
Fibonacci();
fbObj =
new
FizzBizz();
}
[Test]
public
void
FizzBizzPass()
{
var ExpectedResult =
"Fizz"
;
var originalResult =
string
.Empty;
originalResult = fbObj.checkFizzBuzz(6);
Assert.AreEqual(ExpectedResult, originalResult);
}
[Test]
public
void
FizzBizzFail()
{
var ExpectedResult =
"FizzBizz"
;
var originalResult =
string
.Empty;
originalResult = fbObj.checkFizzBuzz(6);
Assert.AreEqual(ExpectedResult, originalResult);
}
[Test]
public
void
DecimalToBinaryPass()
{
var ExpectedResult =
"1000"
;
var originalResult =
string
.Empty;
originalResult = obj.getDecimalNumber(8);
Assert.AreEqual(ExpectedResult, originalResult);
}
[Test]
public
void
DecimalToBinaryFail()
{
var ExpectedResult =
"1001"
;
var originalResult =
string
.Empty;
originalResult = obj.getDecimalNumber(8);
Assert.That(ExpectedResult, Is.EqualTo(originalResult));
}
[Test]
public
void
FibonacciPass()
{
List <
int
> ExpectedResult =
new
List <
int
> ();
var result = fObj.GetFibonacci(1);
ExpectedResult.Add(0);
ExpectedResult.Add(1);
ExpectedResult.Add(1);
CollectionAssert.AreEqual(ExpectedResult, result);
}
[Test]
public
void
FibonacciFail()
{
List <
int
> ExpectedResult =
new
List <
int
> ();
var result = fObj.GetFibonacci(1);
ExpectedResult.Add(0);
ExpectedResult.Add(1);
ExpectedResult.Add(1);
ExpectedResult.Add(2);
CollectionAssert.AreEqual(ExpectedResult, result);
}
}
To test the methods,
Other ways to test
Install NUit
Download
.
Run Nunit and open the test project dll.
Click on run to know the output.
Nuget package
Nunit project
Up Next
Ebook Download
View all
ASP.NET GridView Control Pocket Guide
Read by 10.7k people
Download Now!
Learn
View all
Membership not found