improve C# sanity test

pull/6134/head
Jan Tattermusch 9 years ago
parent 38ed2cfdb5
commit 9c3f15c43b
  1. 28
      src/csharp/Grpc.Core.Tests/SanityTest.cs
  2. 22
      src/csharp/tests.json

@ -38,6 +38,7 @@ using System.Reflection;
using Grpc.Core;
using Grpc.Core.Internal;
using Grpc.Core.Utils;
using Newtonsoft.Json;
using NUnit.Framework;
namespace Grpc.Core.Tests
@ -55,27 +56,23 @@ namespace Grpc.Core.Tests
[Test]
public void TestsJsonUpToDate()
{
var testClasses = DiscoverAllTestClasses();
string testsJson = GetTestsJson();
var discoveredTests = DiscoverAllTestClasses();
string discoveredTestsJson = JsonConvert.SerializeObject(discoveredTests, Formatting.Indented);
// we don't have a JSON parser at hand, but check that the test class
// 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));
}
Assert.AreEqual(discoveredTestsJson, ReadTestsJson());
}
/// <summary>
/// Gets list of all test classes obtained by inspecting all the test assemblies.
/// </summary>
private List<string> DiscoverAllTestClasses()
private Dictionary<string, List<string>> DiscoverAllTestClasses()
{
var assemblies = GetTestAssemblies();
var testClasses = new List<string>();
var testsByAssembly = new Dictionary<string, List<string>>();
foreach (var assembly in assemblies)
{
var testClasses = new List<string>();
foreach (var t in assembly.GetTypes())
{
foreach (var m in t.GetMethods())
@ -89,16 +86,19 @@ namespace Grpc.Core.Tests
}
}
testClasses.Sort();
testsByAssembly.Add(assembly.GetName().Name, testClasses);
}
testClasses.Sort();
return testClasses;
return testsByAssembly;
}
private string GetTestsJson()
/// <summary>
/// Reads contents of tests.json file.
/// </summary>
private string ReadTestsJson()
{
var assemblyDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var testsJsonFile = Path.Combine(assemblyDir, "..", "..", "..", "tests.json");
return File.ReadAllText(testsJsonFile);
}

@ -1,11 +1,5 @@
{
"assemblies": [
"Grpc.Core.Tests",
"Grpc.Examples.Tests",
"Grpc.HealthCheck.Tests",
"Grpc.IntegrationTesting"
],
"tests": [
"Grpc.Core.Tests": [
"Grpc.Core.Internal.Tests.AsyncCallTest",
"Grpc.Core.Internal.Tests.ChannelArgsSafeHandleTest",
"Grpc.Core.Internal.Tests.CompletionQueueEventTest",
@ -32,13 +26,19 @@
"Grpc.Core.Tests.ServerTest",
"Grpc.Core.Tests.ShutdownTest",
"Grpc.Core.Tests.TimeoutsTest",
"Grpc.Core.Tests.UserAgentStringTest",
"Math.Tests.MathClientServerTest",
"Grpc.Core.Tests.UserAgentStringTest"
],
"Grpc.Examples.Tests": [
"Math.Tests.MathClientServerTest"
],
"Grpc.HealthCheck.Tests": [
"Grpc.HealthCheck.Tests.HealthClientServerTest",
"Grpc.HealthCheck.Tests.HealthServiceImplTest",
"Grpc.IntegrationTesting.HistogramTest",
"Grpc.HealthCheck.Tests.HealthServiceImplTest"
],
"Grpc.IntegrationTesting": [
"Grpc.IntegrationTesting.GeneratedClientTest",
"Grpc.IntegrationTesting.GeneratedServiceBaseTest",
"Grpc.IntegrationTesting.HistogramTest",
"Grpc.IntegrationTesting.InteropClientServerTest",
"Grpc.IntegrationTesting.MetadataCredentialsTest",
"Grpc.IntegrationTesting.RunnerClientServerTest",

Loading…
Cancel
Save