Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

create Nunit test cases and use the coverage tool for the following team leader.

ID: 3731334 • Letter: C

Question

create Nunit test cases and use the coverage tool for the following

team leader.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Program10_3

{

class TeamLeader : ProductionWorker

{

private double _monthlyBonus;

private int _requiredTrainingHour;

private int _attendedTrainingHour;

public TeamLeader()

{

_monthlyBonus = MonthlyBonus;

_requiredTrainingHour = RequiredTrainingHour;

_attendedTrainingHour = AttendedTrainingHour;

}

public double MonthlyBonus

{

get

{

return _monthlyBonus;

}

set

{

_monthlyBonus = value;

}

}

public int RequiredTrainingHour

{

get

{

return _requiredTrainingHour;

}

set

{

_requiredTrainingHour = value;

}

}

public int AttendedTrainingHour

{

get

{

return _attendedTrainingHour;

}

set

{

_attendedTrainingHour = value;

}

}

}

}

productionWorker.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Program10_3

{

class ProductionWorker : Employee

{

private int _shiftNum;

private double _hourlyRate;

public ProductionWorker()

{

_shiftNum = ShiftNum;

_hourlyRate = HourlyRate;

}

public int ShiftNum

{

get

{

return _shiftNum;

}

set

{

_shiftNum = value;

}

}

public double HourlyRate

{

get

{

return _hourlyRate;

}

set

{

_hourlyRate = value;

}

}

}

}

employee.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Program10_3

{

class Employee

{

private string _name;

private int _number;

public Employee()

{

_name = Name;

_number = Number;

}

public string Name

{

get

{

return _name;

}

set

{

_name = value;

}

}

public int Number

{

get

{

return _number;

}

set

{

_number = value;

}

}

}

}

Explanation / Answer

Approach i Followed:-

Created one condole application named NUnit Test

3 above classes created with respective inheritance.

In Manage nuget package enabled NUnit test.

Added one new project for NUnit named UnitTestProject1.

Builded console application and added reference in NUnit for Test Data.

Initialised some inputs in class for Testing NUnit cases for Tool->Test Explorer

Called respective classes for Data validation and Added Test Cases

Here we can Call TeamLeader (Because other class inherited here) class and we can check for all values but disadvantage of that is if some where else inherited class used so better to make seperation

Test cases are built by what is req so some common i used like Name and Number

Thanks, please have a look for Sample test bellow

SO following is the sample for test :

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NUnitTest;

namespace UnitTestProject1
{
[TestClass]
public class UnitTest1
{
Employee empObj = new Employee();
//Employee class NUnit tests
[TestMethod]
public void TestEmployee_Name()
{
string EmpName = empObj.Name.ToString();
Assert.IsNotNull(EmpName);
Assert.IsTrue(EmpName.Length > 3 && EmpName.Length < 50);
}

[TestMethod]
public void TestEmployee_Number()
{
int EmpNumber = empObj.Number;
Assert.IsNotNull(EmpNumber);
Assert.IsTrue(EmpNumber > 0 && EmpNumber < 99999999999);
}

//ProductionWorker class NUnit tests
ProductionWorker objPW = new ProductionWorker();

[TestMethod]
public void TestProductionWorker_ShiftNumber()
{
Assert.IsNotNull(objPW.ShiftNumber);
Assert.IsTrue(objPW.ShiftNumber >= 0);
}

[TestMethod]
public void TestProductionWorker_HourlyRate()
{
Assert.IsNotNull(objPW.HourlyRate);
Assert.IsTrue(objPW.HourlyRate > 0.0);
}

//TeamLeader Class NUnit tests
TeamLeader objTL = new TeamLeader();
[TestMethod]
public void TestTeamLeader_MonthlyBonus()
{
Assert.IsTrue(objTL.MonthlyBonus >=0);
}

[TestMethod]
public void TestTeamLeader_RequiredTrainingHour()
{
Assert.IsTrue(objTL.RequiredTrainingHour >=0);
}

[TestMethod]
public void TestTeamLeader_AttendedTrainingHour()
{
Assert.IsTrue(objTL.RequiredTrainingHour >=0);
}
}
}