Having installed version 3.23.0.10 I now get the following message:
"NCrunch is unable to safely execute tests in this assembly because it contains unstable test generation. A previous discovery run over this assembly returned 2627 test cases, but when preparing NUnit to execute tests, there are now 2636 test cases. Usually this is caused by generating tests using TestCaseSource using random, inconsistent or otherwise unstable data."
In this case I am not using TestCaseSource and would appreciate help in resolving the problem.
I have many test files that look like this:
using NUnit.Framework;
namespace BS4Library.DataLayerTests.HotelUpdates.GetHotelUpdatesFromTours
{
[NCrunch.Framework.ExclusivelyUses("ASCIntegration")]
[TestFixture]
public class Tests305 : GenericTests
{
private const int TestNumber = 305;
#region Tests
[Test]
public void TestWithoutPackages()
{
WithoutPackages(TestNumber);
}
[Test]
public void TestPackages()
{
Packages(TestNumber);
}
[Test]
public void TestMealPlans()
{
MealPlans(TestNumber);
}
[Test]
public void TestQuoteTourClasses()
{
QuoteTourClasses(TestNumber);
}
[Test]
public void TestDepartments()
{
Departments(TestNumber);
}
[Test]
public void TestParams()
{
Params(TestNumber);
}
#endregion
#region Private Methods
#endregion
}
}
They inherit from:
using System;
using System.Linq;
using ASCLibrary.Security.BusinessLayer;
using ATG.Constants;
using BS4Library.DataLayerTests.Setup;
using NUnit.Framework;
namespace BS4Library.DataLayerTests.HotelUpdates.GetHotelUpdatesFromTours
{
[NCrunch.Framework.ExclusivelyUses("ASCIntegration")]
[TestFixture]
public class GenericTests : AssertionHelper, IDisposable
{
private SecuritySession _ses;
private ThreadSession _myThread;
private DataLayer.HotelUpdates.HotelUpdatesDataAccessor _da;
private bool _disposed;
private const string LocalHost = "localHost";
private SetupHotelUpdateLines _testing;
#region Tests
internal void WithoutPackages(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
//act
foreach (var test in _testing.HotelUpdateLinesPackages(Constants.HotelUpdateLineTestData.FromTour, null, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
internal void Packages(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
foreach (var package in _testing.Packages)
{
//act
foreach (var test in _testing.HotelUpdateLinesPackages(Constants.HotelUpdateLineTestData.FromTour, package, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
}
internal void MealPlans(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
foreach (var mealPlan in _testing.MealPlans)
{
//act
foreach (var test in _testing.HotelUpdateLinesMealPlans(Constants.HotelUpdateLineTestData.FromTour, mealPlan, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
}
internal void QuoteTourClasses(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
foreach (var tourClass in _testing.QuoteTourClasses)
{
//act
foreach (var test in _testing.HotelUpdateLinesTourClasses(Constants.HotelUpdateLineTestData.FromTour, tourClass, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
}
internal void Departments(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
{
foreach (var department in _testing.Departments)
{
//act
foreach (var test in _testing.HotelUpdateLinesDepartments(Constants.HotelUpdateLineTestData.FromTour, department, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
}
}
internal void Params(int testNumber)
{
//arrange
using (var testing = new TestingSetup())
{
foreach (var param in _testing.Params)
{
//act
foreach (var test in _testing.HotelUpdateLinesParams(Constants.HotelUpdateLineTestData.FromTour, param, testNumber))
{
var records = _da.GetHotelUpdatesFromTours(test.Key, SetupHotelUpdateLines.CancelDays);
//assert
testing.CheckHotelUpdateLines(records.ToList(), test.Value);
}
}
}
}
#endregion
[OneTimeSetUp]
public void SetupData()
{
ClearDownData();
_testing = new SetupHotelUpdateLines();
_ses = new SecuritySession(LocalHost, "ASCTest");
Expect(_ses, Is.Not.Null);
Expect(_ses.Environment, Is.Not.Null);
_myThread = new ThreadSession(_ses, "CreateEditAssignedRole");
_da = new DataLayer.HotelUpdates.HotelUpdatesDataAccessor(_myThread, false);
Expect(_da, Is.Not.Null);
}
[OneTimeTearDown]
public static void ClearDownData()
{
TestingSetup.ClearBS4Data();
}
#region Implementation of IDisposable
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <filterpriority>2</filterpriority>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
#region ProtectedMethods
/// <summary>
/// Free the resources of the class and alter which fields get disposed.
/// </summary>
/// <param name="cleanManaged">Whether to dispose managed objects as well as native ones.</param>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_myThread")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_testing")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_ses")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2213:DisposableFieldsShouldBeDisposed", MessageId = "_da")]
protected virtual void Dispose(bool cleanManaged)
{
if (_disposed)
return;
if (cleanManaged)
{
_ses?.Dispose();
_da?.Dispose();
_testing?.Dispose();
_myThread?.Dispose();
}
_disposed = true;
}
#endregion
#region Private Methods
#endregion
}
}
Currently only one of the test files is throwing the error. If all of them had the same error I may be able to understand it.
The problem does not occur in 3.22.0.1 as the release notes for 3.23.0.10 indicate that this is an extra check introduced in this version.
I appreciate that this may not be the best way to run tests, but my main priority at this stage is to resolve the error.