Skip to content
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
33 changes: 33 additions & 0 deletions docs/docs/migration/mstest.md
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,39 @@ public class MyTests
}
```

### Test Attachments

```csharp
// MSTest
[TestMethod]
public void TestWithAttachment()
{
// Test logic
var logPath = "test-log.txt";
File.WriteAllText(logPath, "test logs");

TestContext.AddResultFile(logPath);
}

// TUnit
[Test]
public async Task TestWithAttachment()
{
// Test logic
var logPath = "test-log.txt";
await File.WriteAllTextAsync(logPath, "test logs");

TestContext.Current!.Output.AttachArtifact(new Artifact
{
File = new FileInfo(logPath),
DisplayName = "Test Log",
Description = "Logs captured during test execution" // Optional
});
}
```

For more information about working with test artifacts, including session-level artifacts and best practices, see the [Test Artifacts guide](../test-lifecycle/artifacts.md).

### Assert.Fail

```csharp
Expand Down
34 changes: 34 additions & 0 deletions docs/docs/migration/nunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Migrating from NUnit to TUnit can significantly improve test execution speed. Be
| `Assert.That(actual, Is.EqualTo(expected))` | `await Assert.That(actual).IsEqualTo(expected)` |
| `Assert.Throws<T>(() => ...)` | `await Assert.ThrowsAsync<T>(() => ...)` |
| `TestContext.WriteLine(...)` | `TestContext` parameter with `context.OutputWriter.WriteLine(...)` |
| `TestContext.AddTestAttachment(path, name)` | `TestContext.Current!.Output.AttachArtifact(new Artifact { File = new FileInfo(path), DisplayName = name })` |
| `CollectionAssert.AreEqual(expected, actual)` | `await Assert.That(actual).IsEquivalentTo(expected)` |
| `StringAssert.Contains(substring, text)` | `await Assert.That(text).Contains(substring)` |

Expand Down Expand Up @@ -247,6 +248,39 @@ public async Task MyTest(TestContext context)
}
```

### Test Attachments

```csharp
// NUnit
[Test]
public void TestWithAttachment()
{
// Test logic
var logPath = "test-log.txt";
File.WriteAllText(logPath, "test logs");

TestContext.AddTestAttachment(logPath, "Test Log");
}

// TUnit
[Test]
public async Task TestWithAttachment()
{
// Test logic
var logPath = "test-log.txt";
await File.WriteAllTextAsync(logPath, "test logs");

TestContext.Current!.Output.AttachArtifact(new Artifact
{
File = new FileInfo(logPath),
DisplayName = "Test Log",
Description = "Logs captured during test execution" // Optional
});
}
```

For more information about working with test artifacts, including session-level artifacts and best practices, see the [Test Artifacts guide](../test-lifecycle/artifacts.md).

### Combinatorial Testing

#### Values and Combinatorial → Matrix
Expand Down
51 changes: 51 additions & 0 deletions docs/docs/migration/xunit.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,57 @@ public class LoggingTests
- Access output via `context.OutputWriter.WriteLine()`
- TestContext provides additional test metadata

#### Test Attachments

xUnit v3 introduced test attachments. TUnit also supports this capability:

**xUnit v3 Code:**
```csharp
public class TestWithAttachments
{
private readonly ITestContextAccessor _testContextAccessor;

public TestWithAttachments(ITestContextAccessor testContextAccessor)
{
_testContextAccessor = testContextAccessor;
}

[Fact]
public async Task Test_WithAttachment()
{
// Test logic
var logPath = "test-log.txt";
await File.WriteAllTextAsync(logPath, "test logs");

_testContextAccessor.Current!.Attachments.Add(
new FileAttachment(logPath, "Test Log"));
}
}
```

**TUnit Equivalent:**
```csharp
public class TestWithAttachments
{
[Test]
public async Task Test_WithAttachment()
{
// Test logic
var logPath = "test-log.txt";
await File.WriteAllTextAsync(logPath, "test logs");

TestContext.Current!.Output.AttachArtifact(new Artifact
{
File = new FileInfo(logPath),
DisplayName = "Test Log",
Description = "Logs captured during test execution" // Optional
});
}
}
```

For more information about working with test artifacts, including session-level artifacts and best practices, see the [Test Artifacts guide](../test-lifecycle/artifacts.md).

### Traits and Categories

#### Trait → Property
Expand Down
Loading
Loading