Skip to content

Commit

Permalink
Allow running tests locally
Browse files Browse the repository at this point in the history
  • Loading branch information
jakublabno committed Dec 19, 2024
1 parent 4a398cf commit fc721dc
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 35 deletions.
18 changes: 0 additions & 18 deletions Dockerfile

This file was deleted.

15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

2 changes: 1 addition & 1 deletion smsapi/smsapi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIconUrl>logo.jpg</PackageIconUrl>
<Nullable>enable</Nullable>
<TargetFrameworks>net6.0;net7.0;net8.0;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<PackageId>SMSAPI.pl</PackageId>
Expand Down
24 changes: 24 additions & 0 deletions smsapiTests/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM debian:12-slim

RUN apt-get update && \
apt-get install -y wget apt-transport-https software-properties-common curl

RUN curl https://packages.microsoft.com/keys/microsoft.asc | tee /etc/apt/trusted.gpg.d/microsoft.asc

RUN wget https://packages.microsoft.com/config/debian/12/prod.list -O /etc/apt/sources.list.d/microsoft-prod.list

RUN curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg

RUN apt-get update && apt-get install -y \
dotnet-sdk-6.0 \
dotnet-sdk-7.0 \
dotnet-sdk-8.0 \
dotnet-sdk-9.0

WORKDIR /app

COPY . .

RUN dotnet restore

RUN dotnet build --configuration Release
21 changes: 21 additions & 0 deletions smsapiTests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DOCKER_IMAGE = smsapi-csharp-client-tests
PROJECT_PATH = smsapiTests/smsapiTests.csproj
DOTNET_VERSIONS = 6.0 7.0 8.0 9.0

.PHONY: build
build:
docker build -t $(DOCKER_IMAGE) -f Dockerfile ../

.PHONY: test
test:
@for version in $(DOTNET_VERSIONS); do \
echo "Running tests on .NET $$version"; \
docker run --rm \
-w /app \
$(DOCKER_IMAGE) \
dotnet test $(PROJECT_PATH) --configuration Release --no-build --framework net$$version; \
done

.PHONY: clean
clean:
docker rmi -f $(DOCKER_IMAGE)
32 changes: 32 additions & 0 deletions smsapiTests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Running Tests Locally with Makefile

This project uses a `Makefile` to simplify the process of running tests locally. The `Makefile` defines the necessary commands to build the Docker image and run tests with multiple .NET versions.

## Prerequisites

Before running tests locally, ensure you have the following installed:

- [Docker](https://www.docker.com/get-started): Docker is used to run the tests inside a container.
- [Make](https://www.gnu.org/software/make/): Make is used to invoke commands defined in the `Makefile`.

## Project Structure

This project includes the following key files and directories:

- `Makefile`: The file that defines the commands for building and testing the project.
- `smsapiTests/`: The directory containing the test project (`smsapiTests.csproj`).
- `Dockerfile`: The file that defines the Docker container used to run the tests.

## Running Tests

The tests are executed inside a Docker container, which ensures that the correct environment is used for all .NET versions specified.

### 1. Build project
```bash
make build
```

### 2. Run tests
```bash
make test
```
3 changes: 2 additions & 1 deletion smsapiTests/smsapiTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
<AssemblyVersion>3.0.0</AssemblyVersion>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
Expand All @@ -12,6 +12,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<PackageReference Include="NunitXml.TestLogger" Version="4.1.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
<ProjectReference Include="..\smsapi\smsapi.csproj" />
<Compile Remove="Contacts\*.cs" />
Expand Down

0 comments on commit fc721dc

Please sign in to comment.