neo-project / neo-devpack-dotnet

NEO Development Pack
MIT License
79 stars 100 forks source link

[TestEngine] Unify coverage check #1074

Closed shargon closed 1 month ago

shargon commented 1 month ago

There are some test contracts that are not checked (or covered) like:

Coverage not found for Neo.SmartContract.Testing.Contract_ABIAttributes2
Coverage not found for Neo.SmartContract.Testing.Contract_ABIAttributes3
Coverage not found for Neo.SmartContract.Testing.Contract_Event
Coverage not found for Neo.SmartContract.Testing.Contract_IndexOrRange
Coverage not found for Neo.SmartContract.Testing.Contract_Logical
Coverage not found for Neo.SmartContract.Testing.Contract_MemberAccess
Coverage not found for Neo.SmartContract.Testing.Contract_MultipleA
Coverage not found for Neo.SmartContract.Testing.Contract_MultipleB
Coverage not found for Neo.SmartContract.Testing.Contract_NEP11
Coverage not found for Neo.SmartContract.Testing.Contract_NEP17
Coverage not found for Neo.SmartContract.Testing.Contract_OnDeployment1
Coverage not found for Neo.SmartContract.Testing.Contract_OnDeployment2
Coverage not found for Neo.SmartContract.Testing.Contract_PostfixUnary
Coverage not found for Neo.SmartContract.Testing.Contract_String
Coverage not found for Neo.SmartContract.Testing.Contract_Throw
shargon commented 1 month ago

Why you dont you tap into their framework? Yes, I know its xunit, but will still work.

Could you show me an example, I can migrate it easily to xunit.

cschuchardt88 commented 1 month ago

https://github.com/neo-project/neo-express/tree/master/src/collector

Example

        var logger = new Moq.Mock<ILogger>();
        var collector = new CodeCoverageCollector(logger.Object);
        collector.TrackTestContract("contract", "registrar.nefdbgnfo");
        collector.LoadTestOutput("run1");
        var coverage = collector.CollectCoverage().ToList();

        var format = new CoberturaFormat();
        Dictionary<string, string> outputMap = new();

        format.WriteReport(coverage, writeAttachment);

        void writeAttachment(string filename, Action<Stream> writeAttachment)
        {
            using var stream = new MemoryStream();
            var text = Encoding.UTF8.GetString(stream.ToArray());
            outputMap.Add(filename, text);
        }