Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TitleWriterTest #77

Merged
merged 1 commit into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Editor/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024 VeyronSakai.
// This software is released under the MIT License.

#if UNITY_EDITOR
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("GhaUnityBuildReporter.Editor.Tests")]
#endif
3 changes: 3 additions & 0 deletions Editor/AssemblyInfo.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Tests.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Tests/Editor.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Tests/Editor/GhaUnityBuildReporter.Editor.Tests.asmdef
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "GhaUnityBuildReporter.Editor.Tests",
"rootNamespace": "GhaUnityBuildReporter.Editor.Tests",
"references": [
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"GhaUnityBuildReporter.Editor"
],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": true,
"precompiledReferences": [
"nunit.framework.dll"
],
"autoReferenced": false,
"defineConstraints": [
"UNITY_INCLUDE_TESTS"
],
"versionDefines": [],
"noEngineReferences": false
}
7 changes: 7 additions & 0 deletions Tests/Editor/GhaUnityBuildReporter.Editor.Tests.asmdef.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tests/Editor/TestData.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Tests/Editor/TestData/ExpectedTitleWriterTestResult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Unity Build Report
3 changes: 3 additions & 0 deletions Tests/Editor/TestData/ExpectedTitleWriterTestResult.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Tests/Editor/TestDoubles.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions Tests/Editor/TestDoubles/SpyJobSummaryRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) 2024 VeyronSakai.
// This software is released under the MIT License.

using System.Diagnostics.CodeAnalysis;
using System.IO;
using GhaUnityBuildReporter.Editor.Domains;

namespace GhaUnityBuildReporter.Editor.Tests.TestDoubles
{
internal sealed class SpyJobSummaryRepository : AbstractJobSummaryRepository
{
private readonly string _outputPath;

internal SpyJobSummaryRepository([NotNull] string outputPath)
{
_outputPath = outputPath;
}

internal override void AppendText(string text)
{
File.AppendAllText(_outputPath, text);
}
}
}
3 changes: 3 additions & 0 deletions Tests/Editor/TestDoubles/SpyJobSummaryRepository.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions Tests/Editor/TitleWriterTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2024 VeyronSakai.
// This software is released under the MIT License.

using System.IO;
using GhaUnityBuildReporter.Editor.Tests.TestDoubles;
using GhaUnityBuildReporter.Editor.UseCases;
using NUnit.Framework;

namespace GhaUnityBuildReporter.Editor.Tests
{
public class TitleWriterTest
{
private readonly string _outputPath =
Path.Combine(Directory.GetCurrentDirectory(), "ActualTitleWriterTestResult.md");

[Test]
public void WriteTest()
{
// Arrange
var jobSummaryRepository = new SpyJobSummaryRepository(_outputPath);
var titleWriter = new TitleWriter(jobSummaryRepository);

// Act
titleWriter.Write();

// Assert
var actual = File.ReadAllText(_outputPath);
var expectedResultPath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory())?.FullName,
"Tests",
"Editor",
"TestData",
"ExpectedTitleWriterTestResult.md"
);
var expected = File.ReadAllText(expectedResultPath);
Assert.AreEqual(expected, actual);
}

[TearDown]
public void TearDown()
{
File.Delete(_outputPath);
}
}
}
11 changes: 11 additions & 0 deletions Tests/Editor/TitleWriterTest.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading