Incorrect Code coverage reporting for C# Object Initializers

Aperta
#216 9 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Tranquilla
Stack tecnologico
csharp
Ambito
testing-qa

Direzione di ricerca

Inizia riproducendo il modello di inizializzatore di oggetti e raccolte segnalato e il suo equivalente con assegnazioni esplicite usando vstest.console 17.14.0-release-25203-01 e 18.0.1-release-25520-05. Confronta i report di coverage risultanti; il lavoro è completato quando le istruzioni di inizializzazione risultano coperte se il percorso del codice viene eseguito completamente, oppure quando la limitazione e il workaround sono documentati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

We are running into an issue where code coverage reports incorrect or partial coverage for certain C# object/collection initializer patterns, even though the code path is fully executed.
Specifically, the following initializer-style pattern is not fully recognized by the coverage tool:

var thing = new Example
{
    name = "object one",
    [1] = '1',
    [2] = '4',
    [3] = '9',
    Size = Math.PI,
    ['C', 4] = "Middle C"
};

To investigate, I ran the impacted tests locally using two versions of vstest.console:
17.14.0-release-25203-01
18.0.1-release-25520-05
In both cases, the coverage results remained unchanged, which suggests this is not resolved by upgrading the test runner.

What we’ve observed is that rewriting the same logic using explicit assignments (instead of initializer-style patterns) results in correct coverage being reported. For example, the following pattern is correctly recognized by the coverage tool:

var thing = new Example();
thing.name = "object one";
thing[1] = '1';
thing[2] = '4';
thing[3] = '9';
thing.Size = Math.PI;
thing['C', 4] = "Middle C";

Based on this, it appears to be a limitation or bug in how the underlying coverage engine handles certain object/collection initializer patterns, rather than an issue with our pipeline or configuration.
If this is a known limitation, or if there is a recommended workaround or escalation path, guidance would be appreciated.
Thanks!

Lingua principale
C#
Stelle
125
Fork
17
Merge medio
1h 17m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/codecoverage

Tutte le issue di microsoft/codecoverage

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.