Passa al contenuto principale

Testing

Flo uses NUnit for backend testing and Jasmine/Karma for frontend testing, with automated coverage reporting via GitHub Actions.

Backend Testing (NUnit + Moq)​

Quick Start​

# Run all tests
dotnet test Flo.BE.Tests

# Run with coverage report
./run-coverage.sh --open

Stats​

MetricValue
FrameworkNUnit with Moq
Test count438+ (1035+ with preference tests)
Line coverage63%
Branch coverage41.9%
Method coverage68.8%
ExcludesMigrations, generated code, Program.cs

Test Structure​

Flo.BE.Tests/
├── Services/
│ ├── AuthServiceTests.cs
│ ├── BookingServiceTests.cs
│ └── ...
├── BoundedContexts/
│ └── Immobili/
│ └── Services/
│ ├── ImmobilePreferenceServiceTests.cs
│ └── ImmobileMatchingServiceTests.cs
└── Controllers/
└── ...

Test Pattern​

[TestFixture]
public class BookingServiceTests
{
private Mock<IBookingRepository> _mockRepo;
private BookingService _service;

[SetUp]
public void SetUp()
{
_mockRepo = new Mock<IBookingRepository>();
_service = new BookingService(_mockRepo.Object);
}

[Test]
public async Task CreateBooking_ValidRequest_ReturnsSuccess()
{
// Arrange
var dto = new CreateBookingDto(1, DateTime.Now, "Notes");

// Act
var result = await _service.CreateAsync(dto);

// Assert
Assert.That(result, Is.Not.Null);
_mockRepo.Verify(x => x.AddAsync(It.IsAny<Booking>()), Times.Once);
}

[TestCase("valid@email.com", true)]
[TestCase("", false)]
public void ValidateEmail_ReturnsExpected(string email, bool expected)
{
var result = _service.IsValidEmail(email);
Assert.That(result, Is.EqualTo(expected));
}
}

Rules​

  • Use NUnit ([Test], [SetUp], [TearDown], Assert.That()) — never xUnit
  • Use Moq for mocking dependencies
  • All backend services require unit tests
  • Follow Arrange-Act-Assert pattern

Frontend Testing​

cd Flo.FE
ng test

Uses Jasmine/Karma with Angular TestBed. All components use OnPush change detection, which must be accounted for in tests.

CI/CD​

Code Coverage​

GitHub Actions runs coverage every 15 days:

  • Executes dotnet test with coverage collection
  • Publishes report to Codecov
  • Badge displayed in README

i18n Check​

CI validates that it.json and en.json have matching translation keys. Fails if any key is missing from either file.

Docker Build​

On push to master or develop:

  • Builds Docker image
  • Publishes to GitHub Container Registry
  • Tags: latest (master), develop-latest (develop), <branch>-<commit> (all)