aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-09 16:25:01 -0700
committerGravatar Jan Tattermusch <jtattermusch@google.com>2016-04-11 11:09:35 -0700
commit9c3f15c43b3e2b68a239639ef13f50391b98a184 (patch)
treeb7530ec452f0bca22109e4dc3e46dc07425c6ad0 /src
parent38ed2cfdb588d2f04a9ce7c4bc352f26c534935d (diff)
improve C# sanity test
Diffstat (limited to 'src')
-rw-r--r--src/csharp/Grpc.Core.Tests/SanityTest.cs28
-rw-r--r--src/csharp/tests.json22
2 files changed, 25 insertions, 25 deletions
diff --git a/src/csharp/Grpc.Core.Tests/SanityTest.cs b/src/csharp/Grpc.Core.Tests/SanityTest.cs
index 343ab1e85a..3830f0cbac 100644
--- a/src/csharp/Grpc.Core.Tests/SanityTest.cs
+++ b/src/csharp/Grpc.Core.Tests/SanityTest.cs
@@ -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);
}
diff --git a/src/csharp/tests.json b/src/csharp/tests.json
index 718bfa3287..f733352a31 100644
--- a/src/csharp/tests.json
+++ b/src/csharp/tests.json
@@ -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",