From f46d4ee8f68cea99d163c58092416942f45c8b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B0=D0=B3=D0=BB=D0=B8=D0=B9=20=D0=90=D0=BD=D1=82?= =?UTF-8?q?=D0=BE=D0=BD=20=D0=9F=D0=B0=D0=B2=D0=BB=D0=BE=D0=B2=D0=B8=D1=87?= <bagliy_ap@studzone.local> Date: Thu, 29 Aug 2019 02:19:03 +0300 Subject: [PATCH] ADD: NUnit XML report analyzer #55 --- Compilers.sln | 6 ++ NunitReportParser/App.config | 6 ++ NunitReportParser/NunitReport.csproj | 58 +++++++++++ NunitReportParser/Program.cs | 102 +++++++++++++++++++ NunitReportParser/Properties/AssemblyInfo.cs | 36 +++++++ NunitReportParser/packages.config | 4 + grades/Grades.json | 57 +++++++++++ 7 files changed, 269 insertions(+) create mode 100644 NunitReportParser/App.config create mode 100644 NunitReportParser/NunitReport.csproj create mode 100644 NunitReportParser/Program.cs create mode 100644 NunitReportParser/Properties/AssemblyInfo.cs create mode 100644 NunitReportParser/packages.config create mode 100644 grades/Grades.json diff --git a/Compilers.sln b/Compilers.sln index 10baea4..fa06cf0 100644 --- a/Compilers.sln +++ b/Compilers.sln @@ -42,6 +42,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestVisitors", "TestVisitor EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestCodeGenerator", "TestCodeGenerator\TestCodeGenerator.csproj", "{186EE1C7-7F34-4428-8A82-F63C8D4368E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NunitReport", "NunitReportParser\NunitReport.csproj", "{88E96425-F1E4-4092-8524-9C13225D2214}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -120,6 +122,10 @@ Global {186EE1C7-7F34-4428-8A82-F63C8D4368E8}.Debug|Any CPU.Build.0 = Debug|Any CPU {186EE1C7-7F34-4428-8A82-F63C8D4368E8}.Release|Any CPU.ActiveCfg = Release|Any CPU {186EE1C7-7F34-4428-8A82-F63C8D4368E8}.Release|Any CPU.Build.0 = Release|Any CPU + {88E96425-F1E4-4092-8524-9C13225D2214}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {88E96425-F1E4-4092-8524-9C13225D2214}.Debug|Any CPU.Build.0 = Debug|Any CPU + {88E96425-F1E4-4092-8524-9C13225D2214}.Release|Any CPU.ActiveCfg = Release|Any CPU + {88E96425-F1E4-4092-8524-9C13225D2214}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NunitReportParser/App.config b/NunitReportParser/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/NunitReportParser/App.config @@ -0,0 +1,6 @@ +п»ї<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> + </startup> +</configuration> \ No newline at end of file diff --git a/NunitReportParser/NunitReport.csproj b/NunitReportParser/NunitReport.csproj new file mode 100644 index 0000000..3dd2c1d --- /dev/null +++ b/NunitReportParser/NunitReport.csproj @@ -0,0 +1,58 @@ +п»ї<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{88E96425-F1E4-4092-8524-9C13225D2214}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>BAgl</RootNamespace> + <AssemblyName>BAgl</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <Deterministic>true</Deterministic> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"> + <HintPath>..\packages\Newtonsoft.Json.12.0.3-beta1\lib\net45\Newtonsoft.Json.dll</HintPath> + <Private>True</Private> + </Reference> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + <None Include="packages.config" /> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> +</Project> \ No newline at end of file diff --git a/NunitReportParser/Program.cs b/NunitReportParser/Program.cs new file mode 100644 index 0000000..97977f0 --- /dev/null +++ b/NunitReportParser/Program.cs @@ -0,0 +1,102 @@ +п»їusing System; +using System.Collections.Generic; +using System.IO; +using System.Xml; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace NunitReport +{ + class ReportParser + { + private static List<XmlNode> cases = new List<XmlNode>(); + + static void ParseTestSuite(XmlNode node) + { + foreach (XmlNode child in node.ChildNodes) + { + if (child.Name == "test-suite") + { + ParseTestSuite(child); + } + else if (child.Name == "test-case") + { + cases.Add(child); + } + } + } + + static void CountGrades() + { + + string configPath = @"../../../grades/Grades.json"; + + JObject grades = JObject.Parse(File.ReadAllText(configPath)); + + JArray tasks = (JArray) grades["Tasks"]; + + var countedGrades = new Dictionary<string, int>(); + foreach (XmlNode testcase in cases) + { + string caseClass = testcase.Attributes["classname"].Value.Split('.')[0]; + string caseName = testcase.Attributes["name"].Value; + + foreach (JObject task in tasks) + { + if ((string) task["name"] == caseClass) + { + int maxGrade = (int) task["grades"][caseName]; + if (testcase.Attributes["result"].Value == "Passed") + { + if (!countedGrades.ContainsKey(caseClass)) + { + countedGrades[caseClass] = 0; + } + countedGrades[caseClass] += maxGrade; + } + } + } + //System.Console.Out.WriteLine(countedGrades[caseClass]); + } + + foreach (KeyValuePair<string, int> g in countedGrades) + { + if (g.Value > 0) + { + System.Console.Out.WriteLine(g.Key + " = " + g.Value.ToString()); + } + } + + } + + static void Main(string[] args) + { + XmlDocument doc = new XmlDocument(); + doc.Load(@"../../../TestResult.xml"); + + // XmlNodeList nodes = doc.DocumentElement.SelectNodes("test-run/test-suite"); + XmlNodeList nodes = doc.DocumentElement.ChildNodes; + + + foreach (XmlNode node in nodes) + { + Console.Out.WriteLine(node.Name); + if (node.Name == "test-suite") + { + ParseTestSuite(node); + } + } + + CountGrades(); + + System.Console.WriteLine("number of running tests: " + cases.Count); + } + } + + class ReportNode + { + public string id; + public string title; + public string author; + } +} \ No newline at end of file diff --git a/NunitReportParser/Properties/AssemblyInfo.cs b/NunitReportParser/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ee0ec91 --- /dev/null +++ b/NunitReportParser/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +п»їusing System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Общие сведения РѕР± этой СЃР±РѕСЂРєРµ предоставляются следующим набором +// набора атрибутов. Рзмените значения этих атрибутов, чтобы изменить сведения, +// связанные СЃРѕ СЃР±РѕСЂРєРѕР№. +[assembly: AssemblyTitle("BAgl")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("BAgl")] +[assembly: AssemblyCopyright("Copyright В© 2019")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Установка значения False для параметра ComVisible делает типы РІ этой СЃР±РѕСЂРєРµ невидимыми +// для компонентов COM. Если необходимо обратиться Рє типу РІ этой СЃР±РѕСЂРєРµ через +// COM, задайте атрибуту ComVisible значение TRUE для этого типа. +[assembly: ComVisible(false)] + +// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM +[assembly: Guid("88e96425-f1e4-4092-8524-9c13225d2214")] + +// Сведения Рѕ версии СЃР±РѕСЂРєРё состоят РёР· следующих четырех значений: +// +// РћСЃРЅРѕРІРЅРѕР№ номер версии +// Дополнительный номер версии +// Номер СЃР±РѕСЂРєРё +// Редакция +// +// Можно задать РІСЃРµ значения или принять номер СЃР±РѕСЂРєРё Рё номер редакции РїРѕ умолчанию. +// используя "*", как показано ниже: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/NunitReportParser/packages.config b/NunitReportParser/packages.config new file mode 100644 index 0000000..8a038e6 --- /dev/null +++ b/NunitReportParser/packages.config @@ -0,0 +1,4 @@ +п»ї<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Newtonsoft.Json" version="12.0.3-beta1" targetFramework="net461" /> +</packages> \ No newline at end of file diff --git a/grades/Grades.json b/grades/Grades.json new file mode 100644 index 0000000..950e0fd --- /dev/null +++ b/grades/Grades.json @@ -0,0 +1,57 @@ +{ + "Tasks": [ + { "name": "TestSimpleLexer", + "grades": { + "TestId": 1, + "TestOps": 1, + "TestKeywords": 1, + "TestOpsFail": 1, + "TestAssigns": 1, + "TestComparisons": 1, + "TestComparisonsAndOps": 1, + "TestComment": 1, + "TestCommentFileEnd": 1, + "TestCommentNextLine": 1, + "TestMultLineComment": 1, + "TestCommentFileEnd": 1, + "TestCommentNextLine": 1, + "TestCommentNotClosed": 1 + } + }, + { "name": "TestLexer", + "grades": { + "TestIntParse": 1, + "TestIntFailDot": 1, + "TestIntFailSymbol": 1, + "TestIntFailEpty": 1, + "TestIntCollectNumber": 1, + "TestIdParse": 1, + "TestIdEmpty": 1, + "TestIdCaps": 1, + "TestIdNumbers": 1, + "TestIdUnderscore" : 1, + "TestIdDot": 1, + "TestIdDollar": 1, + "TestIntNotZeroParse": 1, + "TestIntNotZeroFail": 1, + "TestIntNotZeroPass": 1, + "TestLetterDigitParse": 1, + "TestLetterDigitFail": 1, + "TestLetterListParse": 1, + "TestLetterListFail": 1, + "TestDigitListParse": 1, + "TestDigitListFail": 1, + "TestLetterDigitGroupParse": 1, + "TestLetterDigitGroupFail": 1, + "TestDoubleParse": 1, + "TestDoubleFail": 1, + "TestQuotedStringParse": 1, + "TestQuotedStringFail": 1, + "TestCommentParse": 1, + "TestCommentFail": 1, + "TestIdChainParse": 1, + "TestIdChainFail": 1 + } + } + ] +} \ No newline at end of file -- GitLab