Skip to content

Help get System.Text.Json test coverage to 100% (or close to it) #32341

Open
@ahsonkhan

Description

@ahsonkhan

Let's try to get the test coverage of all components of the JSON stack closer to 100%, where feasible.
We are in pretty good shape (well over 90%+). It tends to be much easier to maintain the bar once we hit 100% since any drop becomes clear/visible.

One component that is effectively at 100% is JsonElement. Let's see if we can get there for the rest.

That said, we shouldn't bend over backwards to try to get to 100% for things like testing all the conditions of a Debug.Asserts or return line after a throw. If some code is unreachable or not used, update/delete it.

Some test improvements are relatively easy to do, so I encourage folks who want to help contribute to System.Text.Json to start there. Others might require more work to bridge the test gap.

 +------------------+--------+--------+--------+
  | Module           | Line   | Branch | Method |
  +------------------+--------+--------+--------+
  | System.Text.Json | 94.04% | 91.22% | 98.05% |
  +------------------+--------+--------+--------+
  +---------+--------+--------+--------+
  |         | Line   | Branch | Method |
  +---------+--------+--------+--------+
  | Total   | 94.04% | 91.22% | 98.05% |
  +---------+--------+--------+--------+
  | Average | 94.04% | 91.22% | 98.05% |
  +---------+--------+--------+--------+

Here's our current JSON test coverage numbers for .NET Core (including outerloop which takes ~10 minutes to generate):
report.zip

Steps to generate:
Following the steps from https://github.com/dotnet/runtime/blob/master/docs/workflow/building/libraries/README.md#quick-start

1) build.cmd clr+libs -rc Release (this step takes ~10-20 minutes)
2) cd src\libraries\System.Text.Json\tests
3) If you want a quick report (~2 minutes), don't run the outerloop tests.
   a) dotnet build /t:Test /p:Coverage=true /p:BuildTargetFramework=net6.0
   b) dotnet build /t:Test /p:Coverage=true /p:BuildTargetFramework=net6.0 /p:Outerloop=true

Here are some good starting points:

  1. JsonDocumentOptions
  • a)
    image
  1. JsonHelpers
    internal static partial class JsonHelpers
  • a)
    image
  • b)
    image
  • c)
    image
  • d)
    image
  1. JsonClassInfo
  • a)
    image
  • b)
    image
  • c)
    image
  1. JsonPropertyInfo
  • a)
    image
  1. JsonPropertyInfoOfTTypeToConvert
    internal sealed class JsonPropertyInfo<TTypeToConvert> : JsonPropertyInfo
  • a)
    image
  1. JsonReaderHelper
  • a)
    image
  1. JsonSerializer
  • a)
    image
  • b)
    image
  • c)
    image
  • d)
    image
  • e)
    image
  • f)
    image
  1. JsonSerializerOptions
  • a)
    image
  1. ArrayConverter
  • a)
    image
  1. ConcurrentStackOfTConverter
  • a)
    image
  1. JsonConverterOfT.cs
    public abstract class JsonConverter<T> : JsonConverter
  • a)
    image
  • b)
    image
  • c)
    image

cc @jozkee, @layomia, @steveharter

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Text.Jsonhelp wanted[up-for-grabs] Good issue for external contributorsincrease-code-coverageTracking need to add more test and increase code coverage of a componenttest-enhancementImprovements of test source code

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions