Skip to content

Commit d394eb8

Browse files
update default ABC settings to be initialized from config
1 parent 4818825 commit d394eb8

14 files changed

+51
-55
lines changed

Testimize.Tests/RealWorldExamples/FormValidationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void GenerateTests() =>
190190
StagnationThresholdPercentage = 0.75,
191191
CoolingRate = 0.95,
192192
AllowMultipleInvalidInputs = false,
193-
OutputGenerator = new NUnitTestCaseAttributeOutputGenerator()
193+
OutputGenerator = new NUnitTestCaseSourceOutputGenerator()
194194
};
195195
})
196196
.Generate();
@@ -368,7 +368,7 @@ public void SubmitForm_WithValidation(
368368
[TestCase("Ann", "a@e.io", "+3598888", "Aa1@abcd", 100, "31-12-2020", "https://example.com", true, "France", new[] { "English", "French" }, "")]
369369
[TestCase("Ann", "a@e.io", "+3598888", "Secure1!", 25, "01-01-1920", "https://very-long-url.com/with/path", true, "Germany", new[] { "German" }, "")]
370370
[TestCase("AAAAAAAAAAAAAAAAAAAA", "a@e.io", "+359888888888", "Aa1@abcd", 18, "01-01-1990", "https://very-long-url.com/with/path", true, "United States", new[] { "German" }, "")]
371-
[Ignore]
371+
[Ignore("")]
372372
public void SuccessMessageDisplayed_WhenSubmitFormWithValidParameters(
373373
string fullName, string email, string phone, string password, int age,
374374
string birthdate, string website, bool? terms, string country, string[] languages, string expectedError)

Testimize.Tests/testimizeSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"testimizeSettings": {
33
"seed": 12345, // used for random data generation
44
"locale": "en", // open TestValueGenerationSettings.cs to see all supported localizations like "en", "fr", "de", "bg", "pl"
5-
"includeBoundaryValues": true,
5+
"allowBoundaryValues": true,
66
"allowValidEquivalenceClasses": true,
77
"allowInvalidEquivalenceClasses": true,
88
"abcGenerationSettings": {

Testimize/samples/PreciseModeCountriesGraphQLTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void GenerateTests() =>
3131
.Valid("BG")
3232
.Valid("FR")
3333
.Invalid("XX").WithExpectedMessage("Country code is invalid")
34-
.Invalid("U1").WithExpectedMessage("Country code must contain only letters")
34+
.Invalid("U1").WithExpectedMessage("Country code must contain only letteABCTestCaseGeneratorTestsrs")
3535
.Invalid("").WithExpectedMessage("Country code is required"))
3636
.AddSingleSelect(s => s
3737
.Valid("en")

Testimize/src/Contracts/IDataProviderStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
namespace Testimize.Contracts;
1818
public interface IDataProviderStrategy
1919
{
20-
List<TestValue> GenerateTestValues(bool? includeBoundaryValues = null, bool? allowValidEquivalenceClasses = null, bool? allowInvalidEquivalenceClasses = null, params TestValue[] preciseTestValues);
20+
List<TestValue> GenerateTestValues(bool? allowBoundaryValues = null, bool? allowValidEquivalenceClasses = null, bool? allowInvalidEquivalenceClasses = null, params TestValue[] preciseTestValues);
2121
}

Testimize/src/OutputGenerators/NUnitTestCaseAttributeOutputGenerator.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@ public override void GenerateOutput(string methodName, IEnumerable<TestCase> tes
2929
var multiInvalidCount = testCases.Count(
3030
tc => tc.Values.Count(v =>
3131
v.Category is TestValueCategory.Invalid or TestValueCategory.BoundaryInvalid) > 1);
32+
var testCasesToBeGenerated = FilterTestCasesByCategory(testCases, testCaseCategory);
33+
Debug.WriteLine($"🧪 Total test cases to be generated: {testCasesToBeGenerated.Count()}");
34+
Console.WriteLine($"\U0001f9ea Total test cases to be generated: {testCasesToBeGenerated.Count()}");
3235

3336
Debug.WriteLine($"🧪 Total test cases with more than one invalid input: {multiInvalidCount}");
3437
Console.WriteLine($"🧪 Total test cases with more than one invalid input: {multiInvalidCount}");
3538

3639
Console.WriteLine("🔹 **Generated NUnit [TestCase(...)] Attributes:**\n");
3740
Debug.WriteLine("🔹 **Generated NUnit [TestCase(...)] Attributes:**\n");
3841

39-
foreach (var testCase in FilterTestCasesByCategory(testCases, testCaseCategory))
42+
foreach (var testCase in testCasesToBeGenerated)
4043
{
4144
var values = testCase.Values.Select(x => ToLiteral(x.Value)).ToList();
4245

Testimize/src/OutputGenerators/NUnitTestCaseSourceOutputGenerator.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ public class NUnitTestCaseSourceOutputGenerator : TestCaseOutputGenerator
2323
{
2424
public override void GenerateOutput(string methodName, IEnumerable<TestCase> testCases, TestCaseCategory testCaseCategory = TestCaseCategory.All)
2525
{
26+
var multiInvalidCount = testCases.Count(
27+
tc => tc.Values.Count(v =>
28+
v.Category is TestValueCategory.Invalid or TestValueCategory.BoundaryInvalid) > 1);
29+
var testCasesToBeGenerated = FilterTestCasesByCategory(testCases, testCaseCategory);
30+
Debug.WriteLine($"🧪 Total test cases to be generated: {testCasesToBeGenerated.Count()}");
31+
Console.WriteLine($"\U0001f9ea Total test cases to be generated: {testCasesToBeGenerated.Count()}");
32+
33+
Debug.WriteLine($"🧪 Total test cases with more than one invalid input: {multiInvalidCount}");
34+
Console.WriteLine($"🧪 Total test cases with more than one invalid input: {multiInvalidCount}");
35+
36+
Console.WriteLine("🔹 **Generated NUnit [TestCase(...)] Attributes:**\n");
37+
Debug.WriteLine("🔹 **Generated NUnit [TestCase(...)] Attributes:**\n");
38+
2639
var sb = new StringBuilder();
2740

2841
sb.AppendLine("\n🔹 **Generated NUnit TestCaseSource Method:**\n");

Testimize/src/Parameters/Core/DataParameter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public DataParameter(
3030
DataProviderStrategy = dataProviderStrategy;
3131

3232
TestValues = DataProviderStrategy.GenerateTestValues(
33-
includeBoundaryValues: preciseMode ? false : includeBoundaryValues, // Disable boundary calculations in manual mode
33+
allowBoundaryValues: preciseMode ? false : includeBoundaryValues, // Disable boundary calculations in manual mode
3434
allowValidEquivalenceClasses: preciseMode ? false : allowValidEquivalenceClasses,
3535
allowInvalidEquivalenceClasses: preciseMode ? false : allowInvalidEquivalenceClasses,
3636
preciseTestValues);

Testimize/src/Settings/ABCGenerationSettings.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
namespace Testimize;
1818
public class ABCGenerationSettings
1919
{
20-
public int TotalPopulationGenerations { get; set; } = 20;
20+
public int TotalPopulationGenerations { get; set; } = 50;
2121
public double MutationRate { get; set; } = 0.3;
2222
public double FinalPopulationSelectionRatio { get; set; } = 0.5;
2323
public double EliteSelectionRatio { get; set; } = 0.5;
2424
public double OnlookerSelectionRatio { get; set; } = 0.1;
2525
public double ScoutSelectionRatio { get; set; } = 0.3;
2626
public bool EnableOnlookerSelection { get; set; } = true;
27-
public bool EnableScoutPhase { get; set; } = false;
27+
public bool EnableScoutPhase { get; set; } = true;
2828
public bool EnforceMutationUniqueness { get; set; } = true;
2929
public double StagnationThresholdPercentage { get; set; } = 0.75;
3030
public double CoolingRate { get; set; } = 0.95;
3131
public bool AllowMultipleInvalidInputs { get; set; } = false;
32-
public ITestCaseOutputGenerator OutputGenerator { get; set; } = new NUnitTestCaseSourceOutputGenerator();
32+
public ITestCaseOutputGenerator OutputGenerator { get; set; } = new NUnitTestCaseAttributeOutputGenerator();
3333

3434
public override int GetHashCode()
3535
{

Testimize/src/Settings/TestimizeSettings.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace Testimize;
1616
public class TestimizeSettings
1717
{
18-
public ABCGenerationSettings ABCGenerationConfig { get; set; }
18+
public ABCGenerationSettings ABCGenerationSettings { get; set; }
1919
/// <summary>
2020
/// Supported locale codes for Bogus:
2121
///
@@ -72,7 +72,7 @@ public class TestimizeSettings
7272
/// </summary>
7373
public string Locale { get; set; } = "en";
7474
public int Seed { get; set; } = 12345;
75-
public bool IncludeBoundaryValues { get; set; } = true;
75+
public bool AllowBoundaryValues { get; set; } = true;
7676
public bool AllowValidEquivalenceClasses { get; set; } = false;
7777
public bool AllowInvalidEquivalenceClasses { get; set; } = false;
7878
public Dictionary<string, InputTypeSettings> InputTypeSettings { get; set; } = new();

Testimize/src/TestValueProviders/Base/BoundaryCapableDataProviderStrategy.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ protected BoundaryCapableDataProviderStrategy(
4646
}
4747

4848
public override List<TestValue> GenerateTestValues(
49-
bool? includeBoundaryValues = null,
49+
bool? allowBoundaryValues = null,
5050
bool? allowValidEquivalenceClasses = null,
5151
bool? allowInvalidEquivalenceClasses = null,
5252
params TestValue[] preciseTestValues)
5353
{
5454
var testValues = base.GenerateTestValues(
55-
includeBoundaryValues: false, // Let us handle boundary addition here
55+
allowBoundaryValues: false, // Let us handle boundary addition here
5656
allowValidEquivalenceClasses,
5757
allowInvalidEquivalenceClasses,
5858
preciseTestValues);
59-
60-
if ((includeBoundaryValues ?? true) && MinBoundary != null && MaxBoundary != null)
59+
var allowBoundaryValuesAnalysis = allowBoundaryValues ?? Config.AllowBoundaryValues;
60+
if (allowBoundaryValuesAnalysis && MinBoundary != null && MaxBoundary != null)
6161
{
6262
testValues.Add(CreateBoundaryTestValue(OffsetValue(MinBoundary.Value, BoundaryOffsetDirection.Before), TestValueCategory.BoundaryInvalid));
6363
testValues.Add(CreateBoundaryTestValue(MinBoundary.Value, TestValueCategory.BoundaryValid));

0 commit comments

Comments
 (0)