Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

An interesting observation on C# code coverage

Introduction Code coverage is an indicator, not an metric. In this post, I will share an example for your entertainment. The code public class Animal { public bool CanTalk { get; init; } public bool CanWalk { get;…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




Introduction



Code coverage is an indicator, not an metric.



In this post, I will share an example for your entertainment.






The code






public class Animal
{
public bool CanTalk { get; init; }
public bool CanWalk { get; init; }
}

public static class AnimalValidator
{
public static bool IsHuman(Animal animal)
{
return animal.CanTalk && animal.CanWalk;
}
}









The good test



Let's test all the input combinations.

It gives us 100% code coverage:




public class AnimalValidatorTest
{
[Theory]
[InlineData(true, true)]
public void IsHuman_WhenAnimalCanTalkAndCanWalk_ReturnsTrue(bool canTalk, bool canWalk)
{
var animal = new Animal { CanTalk = canTalk, CanWalk = canWalk };
var isHuman = AnimalValidator.IsHuman(animal);
Assert.True(isHuman);
}

[Theory]
[InlineData(false, false)]
[InlineData(false, true)]
[InlineData(true, false)]
public void IsHuman_WhenAnimalCannotTalkOrCannotWalk_ReturnsFalse(bool canTalk, bool canWalk)
{
var animal = new Animal { CanTalk = canTalk, CanWalk = canWalk };
var isHuman = AnimalValidator.IsHuman(animal);
Assert.False(isHuman);
}
}









The 100% coverage test



One day, someone removed two test cases because they thought that the tests were running for too long .




[Theory]
// [InlineData(false, false)]
[InlineData(false, true)]
// [InlineData(true, false)]






Interestingly, we still get 100% code coverage.






The explanation



Let's put the code into SharpLab.



This code:




return animal.CanTalk && animal.CanWalk;






will compile into:




if (animal.CanTalk)
{
return animal.CanWalk;
}
return false;






It means:

CanTalk = true contributes 50%.

CanTalk = false contributes 50%.



The value of CanWalk doesn't matter.





The brittleness of 100% coverage test



Another day, someone changed the order of boolean because they thought it would improve performance because majority of animals cannot walk.




public static bool IsHuman(Animal animal)
{
// return animal.CanTalk && animal.CanWalk;
return animal.CanWalk && animal.CanTalk;
}






Now, our test coverage drops from 100% to 50%, because both of our test cases are CanWalk = true.






Conclusion



C# code coverage is based on compiled code.



Writing good unit tests is more important than code coverage.



Hope you find it interesting.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Vulnerability Remediation & Verification
Syntax validiert (0 Fehler)
title: Detect Exploitation - An interesting observation on C# code coverage
id: c2e60763-6d00-47ec-91d2-4c06e8e170cf
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-26
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-26"
        description = "YARA Signature for "
    strings:
        $str = "An interesting observation on " ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("An interesting observation on C code cov")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*An interesting observation on C code cov*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "An interesting observation on C code cov"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich An interesting observation on C# code co.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten An interesting observation on C# code coverage

Thematisch verwandte Begriffe: interesting, observation, code, coverage · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-100620 | Capgo CLI (npm package @capgo/cli) through 7.98.2 is affected by an ove…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag