Exemplo n.º 1
0
        public override void AfterEach(ExtensionContext context)
        {
            Profiler profiler = GetStoredValue(context);

            try
            {
                profiler.Finish();
                if (context.ExecutionException.Present)
                {
                    ExtensionContext.Store testDirStore = GetStore(context, TestDirectoryExtension.TestDirectoryNamespace);
                    TestDirectory          testDir      = ( TestDirectory )testDirStore.get(TestDirectoryExtension.TEST_DIRECTORY);
                    File profileOutputFile   = testDir.CreateFile("profiler-output.txt");
                    FileSystemAbstraction fs = testDir.FileSystem;

                    using (PrintStream @out = new PrintStream(fs.OpenAsOutputStream(profileOutputFile, false)))
                    {
                        string displayName = context.TestClass.map(Type.getSimpleName).orElse("class") + "." + context.DisplayName;
                        profiler.PrintProfile(@out, displayName);
                    }
                }
            }
            catch (Exception e)
            {
                throw new JUnitException("Failed to finish profiling and/or produce profiling output.", e);
            }
        }