Reputation: 3278
I am trying to understand automated
test class generation in Visual Studio. I am using Microsoft Plex Framework
. Here is the details of Pex framework. https://www.microsoft.com/en-us/research/project/pex-and-moles-isolation-and-white-box-unit-testing-for-net/
I have used the code as shown below
public class AuditRepository:BaseDataRepository<AuditItem, int>, IAuditRepository
{
public AuditRepository(string connString, IContainerFactory containerFactory) : base(connString, containerFactory)
{
}
public IEnumerable GetTopAudit(int topCount)
{
const string sql = "SELECT TOP ({0}) * FROM audit ORDER BY CreatedTime DESC";
return Query(string.Format(sql, topCount));
}
}
I have used InteliTest
to create unit test
for above method and which automatically generated the test files and methods
as shown below
/// <summary>This class contains parameterized unit tests for AuditRepository</summary>
[PexClass(typeof(AuditRepository))]
[PexAllowedExceptionFromTypeUnderTest(typeof(InvalidOperationException))]
[PexAllowedExceptionFromTypeUnderTest(typeof(ArgumentException), AcceptExceptionSubtypes = true)]
[TestClass]
public partial class AuditRepositoryTest
{
/// <summary>Test stub for GetTopAudit(Int32)</summary>
[PexMethod]
public IEnumerable GetTopAuditTest([PexAssumeUnderTest]AuditRepository target, int topCount)
{
IEnumerable result = target.GetTopAudit(topCount);
return result;
// TODO: add assertions to method AuditRepositoryTest.GetTopTest(AuditRepository, Int32)
}
}
Now, when I tried to run the test using InteliTest
, it shows warnings and suggested to fix by adding below code [Basically below code generated when clicked on 'Fix' button]
public static partial class AuditRepositoryFactory
{
/// <summary>A factory for Radiometer.RadCon.RAP.Repository.AuditRepository instances</summary>
[PexFactoryMethod(typeof(AuditRepository))]
public static AuditRepository Create(string connString_s, IContainerFactory containerFactory_iContainerFactory)
{
AuditRepository auditRepository
= new AuditRepository(connString_s, containerFactory_iContainerFactory);
return auditRepository;
// TODO: Edit factory method of AuditRepository
// This method should be able to configure the object in all possible ways.
// Add as many parameters as needed,
// and assign their values to each field by using the API.
}
}
I am not able to understand what's going on behind the screen, what does it mean by below commented lines
// TODO: Edit factory method of AuditRepository
// This method should be able to configure the object in all possible ways.
// Add as many parameters as needed,
// and assign their values to each field by using the API.
Upvotes: 0
Views: 329
Reputation: 11889
Do you understand what a factory pattern is for?
The comments are making suggestions on how to create a factory method. Code generation is not clever enough to know how you want to usethis function, so the comments are giving you hints.
BTW, you should probably be returning an interface from your factory method, to make testing easier.
public static IAuditRepository Create(string connString_s, IContainerFactory containerFactory_iContainerFactory)
{ ... }
Upvotes: 1