Skip to content

Commit 584a309

Browse files
authored
Attach output as a file on CI (Azure#23025)
1 parent a08113b commit 584a309

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

sdk/core/Azure.Core.TestFramework/src/RecordedTestBase.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Castle.DynamicProxy;
1010
using NUnit.Framework;
1111
using NUnit.Framework.Interfaces;
12+
using NUnit.Framework.Internal;
1213

1314
namespace Azure.Core.TestFramework
1415
{
@@ -79,7 +80,6 @@ public T InstrumentClientOptions<T>(T clientOptions, TestRecording recording = d
7980
protected string GetSessionFilePath()
8081
{
8182
TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;
82-
8383
string name = new string(testAdapter.Name.Select(c => s_invalidChars.Contains(c) ? '%' : c).ToArray());
8484
string additionalParameterName = testAdapter.Properties.ContainsKey(ClientTestFixtureAttribute.RecordingDirectorySuffixKey) ?
8585
testAdapter.Properties.Get(ClientTestFixtureAttribute.RecordingDirectorySuffixKey).ToString() :
@@ -153,6 +153,13 @@ public virtual void StartTestRecording()
153153
[TearDown]
154154
public virtual void StopTestRecording()
155155
{
156+
if (TestEnvironment.GlobalIsRunningInCI)
157+
{
158+
var tempFileName = Path.GetTempFileName() + ".txt";
159+
File.WriteAllText(tempFileName, TestExecutionContext.CurrentContext.CurrentResult.Output);
160+
TestContext.AddTestAttachment(tempFileName, "Test Output");
161+
}
162+
156163
bool testPassed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed;
157164

158165
if (ValidateClientInstrumentation && testPassed)

0 commit comments

Comments
 (0)