Skip to content
Snippets Groups Projects
Commit 9c3f15c4 authored by Jan Tattermusch's avatar Jan Tattermusch
Browse files

improve C# sanity test

parent 38ed2cfd
No related branches found
No related tags found
No related merge requests found
...@@ -38,6 +38,7 @@ using System.Reflection; ...@@ -38,6 +38,7 @@ using System.Reflection;
using Grpc.Core; using Grpc.Core;
using Grpc.Core.Internal; using Grpc.Core.Internal;
using Grpc.Core.Utils; using Grpc.Core.Utils;
using Newtonsoft.Json;
using NUnit.Framework; using NUnit.Framework;
namespace Grpc.Core.Tests namespace Grpc.Core.Tests
...@@ -55,27 +56,23 @@ namespace Grpc.Core.Tests ...@@ -55,27 +56,23 @@ namespace Grpc.Core.Tests
[Test] [Test]
public void TestsJsonUpToDate() public void TestsJsonUpToDate()
{ {
var testClasses = DiscoverAllTestClasses(); var discoveredTests = DiscoverAllTestClasses();
string testsJson = GetTestsJson(); string discoveredTestsJson = JsonConvert.SerializeObject(discoveredTests, Formatting.Indented);
// we don't have a JSON parser at hand, but check that the test class Assert.AreEqual(discoveredTestsJson, ReadTestsJson());
// name is contained in the file instead.
foreach (var className in testClasses) {
Assert.IsTrue(testsJson.Contains(className),
string.Format("Test class \"{0}\" is missing in C# tests.json file", className));
}
} }
/// <summary> /// <summary>
/// Gets list of all test classes obtained by inspecting all the test assemblies. /// Gets list of all test classes obtained by inspecting all the test assemblies.
/// </summary> /// </summary>
private List<string> DiscoverAllTestClasses() private Dictionary<string, List<string>> DiscoverAllTestClasses()
{ {
var assemblies = GetTestAssemblies(); var assemblies = GetTestAssemblies();
var testClasses = new List<string>(); var testsByAssembly = new Dictionary<string, List<string>>();
foreach (var assembly in assemblies) foreach (var assembly in assemblies)
{ {
var testClasses = new List<string>();
foreach (var t in assembly.GetTypes()) foreach (var t in assembly.GetTypes())
{ {
foreach (var m in t.GetMethods()) foreach (var m in t.GetMethods())
...@@ -89,16 +86,19 @@ namespace Grpc.Core.Tests ...@@ -89,16 +86,19 @@ namespace Grpc.Core.Tests
} }
} }
testClasses.Sort();
testsByAssembly.Add(assembly.GetName().Name, testClasses);
} }
testClasses.Sort(); return testsByAssembly;
return testClasses;
} }
private string GetTestsJson() /// <summary>
/// Reads contents of tests.json file.
/// </summary>
private string ReadTestsJson()
{ {
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tests.json"); var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tests.json");
return File.ReadAllText(testsJsonFile); return File.ReadAllText(testsJsonFile);
} }
......
{ {
"assemblies": [ "Grpc.Core.Tests": [
"Grpc.Core.Tests",
"Grpc.Examples.Tests",
"Grpc.HealthCheck.Tests",
"Grpc.IntegrationTesting"
],
"tests": [
"Grpc.Core.Internal.Tests.AsyncCallTest", "Grpc.Core.Internal.Tests.AsyncCallTest",
"Grpc.Core.Internal.Tests.ChannelArgsSafeHandleTest", "Grpc.Core.Internal.Tests.ChannelArgsSafeHandleTest",
"Grpc.Core.Internal.Tests.CompletionQueueEventTest", "Grpc.Core.Internal.Tests.CompletionQueueEventTest",
...@@ -32,13 +26,19 @@ ...@@ -32,13 +26,19 @@
"Grpc.Core.Tests.ServerTest", "Grpc.Core.Tests.ServerTest",
"Grpc.Core.Tests.ShutdownTest", "Grpc.Core.Tests.ShutdownTest",
"Grpc.Core.Tests.TimeoutsTest", "Grpc.Core.Tests.TimeoutsTest",
"Grpc.Core.Tests.UserAgentStringTest", "Grpc.Core.Tests.UserAgentStringTest"
"Math.Tests.MathClientServerTest", ],
"Grpc.Examples.Tests": [
"Math.Tests.MathClientServerTest"
],
"Grpc.HealthCheck.Tests": [
"Grpc.HealthCheck.Tests.HealthClientServerTest", "Grpc.HealthCheck.Tests.HealthClientServerTest",
"Grpc.HealthCheck.Tests.HealthServiceImplTest", "Grpc.HealthCheck.Tests.HealthServiceImplTest"
"Grpc.IntegrationTesting.HistogramTest", ],
"Grpc.IntegrationTesting": [
"Grpc.IntegrationTesting.GeneratedClientTest", "Grpc.IntegrationTesting.GeneratedClientTest",
"Grpc.IntegrationTesting.GeneratedServiceBaseTest", "Grpc.IntegrationTesting.GeneratedServiceBaseTest",
"Grpc.IntegrationTesting.HistogramTest",
"Grpc.IntegrationTesting.InteropClientServerTest", "Grpc.IntegrationTesting.InteropClientServerTest",
"Grpc.IntegrationTesting.MetadataCredentialsTest", "Grpc.IntegrationTesting.MetadataCredentialsTest",
"Grpc.IntegrationTesting.RunnerClientServerTest", "Grpc.IntegrationTesting.RunnerClientServerTest",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment