This document describes how to run tests for SharpSync, including integration tests that require external services.
# Run all unit tests (no external services required)
dotnet test
# Run with verbose output
dotnet test --verbosity normalSharpSync includes integration tests for storage backends that require real servers (e.g., SFTP). These tests are automatically skipped unless you provide the necessary configuration.
SFTP integration tests require a running SFTP server. You have two options:
The easiest way to run SFTP integration tests locally:
# Start SFTP server
docker-compose -f docker-compose.test.yml up -d
# Wait for server to be ready (about 5 seconds)
sleep 5
# Run tests with environment variables
export SFTP_TEST_HOST=localhost
export SFTP_TEST_PORT=2222
export SFTP_TEST_USER=testuser
export SFTP_TEST_PASS=testpass
export SFTP_TEST_ROOT=/home/testuser/upload
dotnet test --verbosity normal
# Stop SFTP server when done
docker-compose -f docker-compose.test.yml downOr use a one-liner:
docker-compose -f docker-compose.test.yml up -d && \
sleep 5 && \
SFTP_TEST_HOST=localhost SFTP_TEST_PORT=2222 SFTP_TEST_USER=testuser SFTP_TEST_PASS=testpass SFTP_TEST_ROOT=/home/testuser/upload dotnet test --verbosity normal && \
docker-compose -f docker-compose.test.yml downIf you have access to an SFTP server, configure it with these environment variables:
export SFTP_TEST_HOST=your-sftp-server.com
export SFTP_TEST_PORT=22
export SFTP_TEST_USER=your-username
export SFTP_TEST_PASS=your-password # For password authentication
# OR
export SFTP_TEST_KEY=/path/to/private-key # For key-based authentication
export SFTP_TEST_ROOT=/path/on/server
dotnet test --verbosity normalNote: The test suite will create and clean up test directories under SFTP_TEST_ROOT.
To test with SSH key authentication:
# Generate test key (if needed)
ssh-keygen -t rsa -b 2048 -f ~/.ssh/sharpsync_test -N ""
# Add key to your SFTP server's authorized_keys
# Run tests
export SFTP_TEST_HOST=localhost
export SFTP_TEST_PORT=2222
export SFTP_TEST_USER=testuser
export SFTP_TEST_KEY=~/.ssh/sharpsync_test
export SFTP_TEST_ROOT=/home/testuser/upload
dotnet test --verbosity normalWebDAV integration tests verify connectivity, file operations, and server capability detection against a real WebDAV server. The tests are located in tests/SharpSync.Tests/Storage/WebDavStorageTests.cs.
# Using Docker Compose (starts the WebDAV server along with other test services)
docker-compose -f docker-compose.test.yml up -d
export WEBDAV_TEST_URL=http://localhost:8080/webdav
export WEBDAV_TEST_USER=testuser
export WEBDAV_TEST_PASS=testpass
dotnet test --verbosity normalLike other integration tests, WebDAV tests skip automatically when the required environment variables are not set.
The GitHub Actions workflow automatically runs all tests, including SFTP integration tests, using a Docker-based SFTP server. See .github/workflows/dotnet.yml for the configuration.
Tests are organized into the following categories:
- No external dependencies
- Fast execution
- Always run
- Located in
tests/SharpSync.Tests/
- Require external services (SFTP, WebDAV, etc.)
- Slower execution
- Only run when configured
- Skip automatically if environment variables not set
# Run tests from a specific file
dotnet test --filter "FullyQualifiedName~SftpStorageTests"
# Run a specific test method
dotnet test --filter "FullyQualifiedName~SftpStorageTests.TestConnectionAsync_ValidCredentials_ReturnsTrue"
# Run all unit tests (excluding integration tests)
# Integration tests will skip automatically without environment variables
dotnet test
# Run only integration tests
dotnet test --filter "FullyQualifiedName~IntegrationTests"To generate test coverage reports:
# Install coverage tool
dotnet tool install --global dotnet-coverage
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"
# View coverage report
# Report will be in TestResults/{guid}/coverage.cobertura.xmlProblem: SFTP integration tests show as "Skipped" in test results.
Solution: This is expected behavior when environment variables are not set. The tests are designed to skip gracefully rather than fail. Set the required environment variables to enable them.
Problem: Tests fail with "Connection refused" error.
Solution:
- Ensure Docker service is running
- Check if port 2222 is already in use:
lsof -i :2222(on Unix) ornetstat -ano | findstr :2222(on Windows) - Verify SFTP container is healthy:
docker-compose -f docker-compose.test.yml ps
Problem: Tests fail with "Authentication failed" error.
Solution:
- Verify environment variables are set correctly
- For key-based auth, ensure the key file exists and has correct permissions:
chmod 600 ~/.ssh/sharpsync_test - Check if the key is in the correct format (OpenSSH format)
Problem: Tests hang or timeout.
Solution:
- Increase test timeout in test settings
- Check network connectivity to SFTP server
- Ensure SFTP server is not overloaded
When adding new integration tests:
- Check for environment variables at the start of the test
- Use
SkipIfIntegrationTestsDisabled()helper method - Clean up resources after test completion
- Use unique paths/names to avoid conflicts with parallel test execution
- Document required environment variables in test class summary
Example:
[Fact]
public async Task MyNewIntegrationTest() {
SkipIfIntegrationTestsDisabled();
_storage = CreateStorage();
// Test code here
// Cleanup is handled in Dispose()
}Performance benchmarks using BenchmarkDotNet are planned for a future release.