Skip to content

[EXPERIMENTAL] Autogenerated unittests - evaluating usability #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JanKrivanek
Copy link
Collaborator

Context

Generated with very early preview of unit tests generation tool. Trying to evaluate if there is any hope of that being useful and what would need to be worked on to achieve usefulness.

Technical data

Baseline (main):

Test summary: total: 85, failed: 3, succeeded: 81, skipped: 1, duration: 6.9s

Target (generated):

Test summary: total: 690, failed: 56, succeeded: 634, skipped: 0, duration: 6.0s
AssemblyName LineRateBefore LineRateAfter LineRateDiff BranchRateBefore BranchRateAfter BranchRateDiff
StructuredLogger 19.61 % 26.72 % 7.11 % 15.69 % 18.63 % 2.93 %
StructuredLogger.Utils 0.00 % 9.47 % 9.47 % 0.00 % 3.75 % 3.75 %

More comments

  • Still just heuristical version (so might not follow convention and references of the repo)
  • Very few and dummy code fixers - so we fallback a lot to commenting out tests with compilation diagnostic
  • No runtime feedback yet - so tests that crash/fail during runtime are kept

Copy link
Collaborator Author

@JanKrivanek JanKrivanek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick pass to capture some obvious misses

/// <summary>
/// Minimal stub implementation of Task for unit testing.
/// </summary>
public class Task
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is useless, as it doesn't extend/inherit tested code. It actually yields the tests incompilable

// // build.EvaluationFolder = evalFolder;
// //
// // // Act & Assert
// // var exception = Record.Exception(() => new Microsoft.Build.Logging.StructuredLogger.ProjectReferenceGraph(build));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Record here conflicted between Xunit and Microsoft.Build.Logging namespaces (later got the precedence)
But this would be hard to catch

/// <summary>
/// Tests that the parameterized constructor correctly assigns properties and that the Message property returns the formatted string when LoadingInitiator is provided.
/// </summary>
[Fact]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and above should have been a data driven tests

/// Tests that calling ReadRecords with a non-existent file path throws an exception.
/// </summary>
[Fact]
public void ReadRecords_String_NonExistentFile_ThrowsException()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a duplicate of ReadBuild_String_NonExistentFile_ThrowsFileNotFoundException with less specific exception - so it's superfluous

/// <summary>
/// A fake Progress implementation to capture progress reports during tests.
/// </summary>
public class FakeProgress : Progress<ProgressUpdate>, Progress
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again - 'hand-mocking' went wrong - it mixes System.Progress StructuredLogger.Progress

/// This test sets all properties using sample values, including edge cases like empty and null strings.
/// </summary>
[Fact]
public void Properties_SetterAndGetter_ShouldWorkCorrectly()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels as a very low value test.
We might want to skip autoprops etc.

@Janek91
Copy link
Contributor

Janek91 commented Apr 22, 2025

@JanKrivanek How did you generate these tests?

@JanKrivanek
Copy link
Collaborator Author

@JanKrivanek How did you generate these tests?

@Janek91 - Research project :-)

Repository owner deleted a comment May 10, 2025
Repository owner deleted a comment May 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants