Skip to content
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

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

Open
6 of 23 tasks
ahsonkhan opened this issue Feb 14, 2020 · 16 comments
Open
6 of 23 tasks

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

ahsonkhan opened this issue Feb 14, 2020 · 16 comments
Labels
area-System.Text.Json help wanted [up-for-grabs] Good issue for external contributors increase-code-coverage Tracking need to add more test and increase code coverage of a component test-enhancement Improvements of test source code
Milestone

Comments

@ahsonkhan
Copy link
Member

ahsonkhan commented Feb 14, 2020

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

@ahsonkhan ahsonkhan added good first issue Issue should be easy to implement, good for first-time contributors increase-code-coverage Tracking need to add more test and increase code coverage of a component test-enhancement Improvements of test source code help wanted [up-for-grabs] Good issue for external contributors labels Feb 14, 2020
@ahsonkhan ahsonkhan added this to the 5.0 milestone Feb 14, 2020
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added area-System.Text.Json untriaged New issue has not been triaged by the area owner labels Feb 14, 2020
@ahsonkhan ahsonkhan removed the untriaged New issue has not been triaged by the area owner label Feb 14, 2020
@alanisaac
Copy link
Contributor

I can pick up some of this work, so long as it'd be OK for a first contribution to the dotnet runtime. I've started on a couple in a draft PR (#32705), and will continue to work through them.

@alexvy86
Copy link
Contributor

alexvy86 commented Apr 2, 2020

@ahsonkhan I started looking into this and ran into an issue running the tests, which I then traced to the fact that the RebuildAndTest target was recently removed. Maybe you want to update the commands in the description of this issue? (/t:RebuildAndTest becomes /t:Test)

   a) dotnet msbuild /t:Test /p:Coverage=true
   b) dotnet msbuild /t:Test /p:Coverage=true /p:Outerloop=true

@jozkee
Copy link
Member

jozkee commented Apr 2, 2020

@alexvy86 done; thanks for pointing that out.

@ahsonkhan
Copy link
Member Author

I started looking into this and ran into an issue running the tests

Do the build instructions need to be updated as well (step 1) or did that work as expected for you? I know there were some recent changes there too (cc @ViktorHofer).

@alexvy86
Copy link
Contributor

alexvy86 commented Apr 3, 2020

The build worked fine, it was only running the tests that wasn't working.

@thall90
Copy link

thall90 commented Apr 19, 2020

I'm looking at testing portions of 2 (JsonHelpers) for a first-time contribution, and was wondering:
is it acceptable to expose internal classes for testing with something like [assembly: InternalsVisibleTo("System.Text.Json.Tests")], or should these classes be tested via outcomes of areas calling their methods?

@jozkee
Copy link
Member

jozkee commented Apr 20, 2020

@thall90 My understanding is that we should avoid using InternalsVisibleTo on test projects as much as we can, I think there has also been efforts to remove its usage on several projects.
See related discussions:
dotnet/corefx#42879 (comment)
#14520 (comment)

@thall90
Copy link

thall90 commented Apr 20, 2020

Sounds good. Thanks!

JoshSchreuder pushed a commit to JoshSchreuder/runtime that referenced this issue May 23, 2020
JoshSchreuder pushed a commit to JoshSchreuder/runtime that referenced this issue May 23, 2020
layomia pushed a commit that referenced this issue May 26, 2020
* Remove unused method on JsonClassInfo (#32341)

* Add test coverage for a couple of validation branches in JsonWriterHelper (#32341)

Co-authored-by: Josh Schreuder <[email protected]>
@layomia layomia removed this from the 5.0.0 milestone Jun 30, 2020
@KimKiHyuk
Copy link
Contributor

KimKiHyuk commented Aug 12, 2020

@thall90 you still work in progress on JsonHelpers?

if not, i hope to take it

@GMous
Copy link

GMous commented Sep 19, 2020

It looks like the steps to generate coverage report need to be updated. Parameters "-subsetCategory" are no longer available. New version:
build.cmd -subset Clr -c Release && build.cmd -subset Libraries /p:CoreCLRConfiguration=Release

@ViktorHofer
Copy link
Member

ViktorHofer commented Sep 19, 2020

build.cmd clr+libs -c Release

@z77ma
Copy link

z77ma commented Oct 18, 2020

Hey guys. Wanted to get an actual coverage report, but the tests/report generating working sooo slow which confuses me a bit, I'm certain I missed smth and I'd appreciate an advice here. If it's important, then builds in both Debug and Release configuration are fine and take 'normal' time for such big code-base.

@ViktorHofer
Copy link
Member

but the tests/report generating working sooo slow which confuses me a bit, I'm certain I missed smth and I'd appreciate an advice here.

hey @z77ma, what do you mean by slow? Do you have data to share?

@jozkee
Copy link
Member

jozkee commented Oct 19, 2020

@z77ma @ViktorHofer it sounds like the runtime subset was built on Debug configuration.

@z77ma did you build using the suggested configuration?

build.cmd clr+libs -c Release

@ahsonkhan
Copy link
Member Author

ahsonkhan commented Oct 20, 2020

I updated the instructions in the original post of the issue:

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 (which would take ~10 minutes).
   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

@z77ma
Copy link

z77ma commented Nov 1, 2020

Hey all.
@ViktorHofer, well I didn't preserve any results from that runs, but the longest attempt I had the patience to wait for lasted for approx. 3h and I killed the process afterward.
@jozkee, yes, I did use the suggested configuration. Basically, my question came as a result of an unexpected duration of a test run in Release configuration.
Anyway, today I tried to repeat all steps from scratch in order to provide more information and some statistics for you. And the issue seems to be gone. Though I can't completely explain what caused the described behavior. The things that differ from my previous attempt are: I build the whole runtime on Release configuration (build.cmd -c Release) and then I used the build command with the -rc flag, as @ahsonkhan suggested.
None of the above doesn't convince me to be a cure. So all looks like I messed smth with the configurations and run tests on Debug build.
I appreciate your help and suggestions. Cheers)

@eiriktsarpalis eiriktsarpalis removed the good first issue Issue should be easy to implement, good for first-time contributors label Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Text.Json help wanted [up-for-grabs] Good issue for external contributors increase-code-coverage Tracking need to add more test and increase code coverage of a component test-enhancement Improvements of test source code
Projects
None yet
Development

No branches or pull requests