Skip to content

Commit

Permalink
[chore] Integration test, part 1 (#482)
Browse files Browse the repository at this point in the history
- Sync C# lang version used for source code + unit tests
- New "EasyPost.Integration" project to test integration versus unit tests
- Rename VB and FSharp projects to more explicitly testing compatibility versus unit tests
- Clarify that EasyPost.Tests (unit tests) can access internal properties of library, integration and compatibility tests cannot
- Update Makefile, GitHub CI to handle/test new unit + integration + compatibility test sets
  • Loading branch information
nwithan8 authored May 30, 2023
1 parent 7d13a69 commit 7ab8d66
Show file tree
Hide file tree
Showing 11 changed files with 133 additions and 34 deletions.
54 changes: 43 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ jobs:

# Run the unit tests in a specific framework (verify that the library works in that framework)
- name: Run Tests
run: make test-fw fw=${{ matrix.framework }}

FSharp_Compatibility:
run: make unit-test fw=${{ matrix.framework }}
Integration_Tests:
runs-on: windows-2022
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -202,14 +202,13 @@ jobs:
- name: Set up dotnet tools and dependencies
run: make install

# Build the test project
- name: Build Solution
run: msbuild EasyPost.Tests.FSharp\EasyPost.Tests.FSharp.fsproj /p:platform="Any CPU" /p:configuration="Debug" /p:outputPath="bin/Test" /p:target="Rebuild" -restore
# Run the integration tests
- name: Run Tests
run: make integration-test fw=net7.0 # Always run integration tests on the latest framework

Visual_Basic_Compatibility:
FSharp_Compatibility_Tests:
runs-on: windows-2022
steps:

- uses: actions/checkout@v3
with:
submodules: true
Expand All @@ -235,9 +234,42 @@ jobs:
- name: Set up dotnet tools and dependencies
run: make install

# Build the test project
- name: Build Solution
run: msbuild EasyPost.Tests.VB\EasyPost.Tests.VB.vbproj /p:platform="Any CPU" /p:configuration="Debug" /p:outputPath="bin/Test" /p:target="Rebuild" -restore
# Run the compatibility tests
- name: Run Tests
run: make fs-compat-test fw=net7.0 # Always run compatibility tests on the latest framework

Visual_Basic_Compatibility_Test:
runs-on: windows-2022
steps:

- uses: actions/checkout@v3
with:
submodules: true

- name: Install .NET SDK
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.x.x

- name: Setup MSBuild
uses: microsoft/[email protected]

- name: Setup Nuget
uses: NuGet/[email protected]

- name: Setup VSTest
uses: darenm/[email protected]

- name: Restore NuGet Packages
run: make restore

# Pull in fixtures submodule
- name: Set up dotnet tools and dependencies
run: make install

# Run the compatibility tests
- name: Run Tests
run: make vb-compat-test fw=net7.0 # Always run compatibility tests on the latest framework


# .NET Standard notes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
<TargetFramework>net7.0</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<RootNamespace>EasyPost.Compatibility.FSharp</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Compile Include="FSharpCompileTest.fs"/>
<Compile Include="FSharpCompileTest.fs" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EasyPost\EasyPost.csproj"/>
<ProjectReference Include="..\EasyPost\EasyPost.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.3.0, 18.0.0)"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="[17.3.0, 18.0.0)" />
<PackageReference Include="coverlet.collector" Version="[3.1.2, 4.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="NETStandard.Library" Version="[2.0.3, 3.0.0)"/>
<PackageReference Include="xunit" Version="[2.4.2, 3.0.0)"/>
<PackageReference Include="NETStandard.Library" Version="[2.0.3, 3.0.0)" />
<PackageReference Include="xunit" Version="[2.4.2, 3.0.0)" />
<PackageReference Include="xunit.runner.visualstudio" Version="[2.4.5, 3.0.0)">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This test checks that EasyPost C# code can be used in F#.
// This test project is running on .NET 7.0, although a success here should mean a success in all versions of .NET.'

namespace EasyPost.Tests.FSharp
namespace EasyPost.Compatibility.FSharp

open EasyPost
open Xunit
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>EasyPost.Tests.VB</RootNamespace>
<RootNamespace>EasyPost.Compatibility.VB</RootNamespace>
<TargetFramework>net7.0</TargetFramework>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions EasyPost.Integration/Basics.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Xunit;

namespace EasyPost.Integration;

public class Basics
{
[Fact]
public void Test1()
{
}
}
27 changes: 27 additions & 0 deletions EasyPost.Integration/EasyPost.Integration.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<RootNamespace>EasyPost.Integration</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion EasyPost.Tests/EasyPost.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RootNamespace>EasyPost.Tests</RootNamespace>

<Nullable>enable</Nullable>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>

Expand Down
10 changes: 8 additions & 2 deletions EasyPost.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ VisualStudioVersion = 16.0.31205.134
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyPost.Tests", "EasyPost.Tests\EasyPost.Tests.csproj", "{16F86382-A5DA-4E2A-A5DC-10B38089256D}"
EndProject
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EasyPost.Tests.VB", "EasyPost.Tests.VB\EasyPost.Tests.VB.vbproj", "{E4E916C4-A35B-4EA4-90D7-5418978C0F34}"
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EasyPost.Compatibility.VB", "EasyPost.Compatibility.VB\EasyPost.Compatibility.VB.vbproj", "{E4E916C4-A35B-4EA4-90D7-5418978C0F34}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "EasyPost.Tests.FSharp", "EasyPost.Tests.FSharp\EasyPost.Tests.FSharp.fsproj", "{D264E3CC-396C-43B5-AFEA-02E50E61E2E4}"
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "EasyPost.Compatibility.FSharp", "EasyPost.Compatibility.FSharp\EasyPost.Compatibility.FSharp.fsproj", "{D264E3CC-396C-43B5-AFEA-02E50E61E2E4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyPost", "EasyPost\EasyPost.csproj", "{047A1600-2E08-4E19-8B71-7BAFE107C119}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyPost.Integration", "EasyPost.Integration\EasyPost.Integration.csproj", "{AC3FD754-C311-439B-9612-F13F0C6D5767}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,6 +32,10 @@ Global
{047A1600-2E08-4E19-8B71-7BAFE107C119}.Debug|Any CPU.Build.0 = Debug|Any CPU
{047A1600-2E08-4E19-8B71-7BAFE107C119}.Release|Any CPU.ActiveCfg = Release|Any CPU
{047A1600-2E08-4E19-8B71-7BAFE107C119}.Release|Any CPU.Build.0 = Release|Any CPU
{AC3FD754-C311-439B-9612-F13F0C6D5767}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AC3FD754-C311-439B-9612-F13F0C6D5767}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AC3FD754-C311-439B-9612-F13F0C6D5767}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AC3FD754-C311-439B-9612-F13F0C6D5767}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
5 changes: 4 additions & 1 deletion EasyPost/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

// Make "internal" methods testable.
#if DEBUG
[assembly: InternalsVisibleTo("EasyPost.Tests")]
[assembly: InternalsVisibleTo("EasyPost.Tests")] // EasyPost.Tests can access internal classes/methods (unit testing).
// EasyPost.Compatibility.FSharp cannot access internal classes/methods (integration/end-user experience).
// EasyPost.Compatibility.VB cannot access internal classes/methods (integration/end-user experience).
// EasyPost.Integration cannot access internal classes/methods (integration/end-user experience).
#endif

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
43 changes: 31 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ clean:
dotnet clean
rm -rf *.nupkg

## coverage - Generate coverage reports for the project
## coverage - Generate coverage reports (unit tests, not integration) for the project
coverage:
bash scripts/unix/generate_test_reports.sh

Expand Down Expand Up @@ -57,11 +57,11 @@ install: | install-tools
git submodule init
git submodule update

## lint - Lints the solution (EasyPost + Tests + F#/VB samples) (check IDE and SA rule violations)
## lint - Lints the solution (EasyPost + Tests + Integration + F#/VB compatibilities) (check IDE and SA rule violations)
lint:
# Lint the source code with dotnet-format
# Lint the project code with dotnet-format
dotnet tool run dotnet-format --no-restore --check
# Lint the source code by building with the "Linting" configuration (will trigger StyleCop)
# Lint the source code (only EasyPost, no tests et. al) by building with the "Linting" configuration (will trigger StyleCop)
dotnet build EasyPost/EasyPost.csproj -c "Linting" -t:Rebuild -restore -p:EnforceCodeStyleInBuild=true

## lint-scripts - Lint and validate the Batch scripts (Windows only)
Expand All @@ -85,7 +85,7 @@ release:
restore:
dotnet restore

## scan - Scan the solution (EasyPost + Tests + F#/VB samples) for security issues (must run install-scanner first)
## scan - Scan the solution (EasyPost + Tests + Integration + F#/VB compatibilities) for security issues (must run install-scanner first)
scan:
dotnet tool run security-scan --verbose --no-banner --ignore-msbuild-errors EasyPost.sln
# "--ignore-msbuild-errors" needed since MSBuild does not like F#: https://github.com/security-code-scan/security-code-scan/issues/235
Expand All @@ -98,15 +98,34 @@ setup-win:
setup-unix:
bash scripts/unix/setup.sh

## test - Test the project
## test - Run all tests in all projects (unit + integration + compatibility)
## EasyPost.Tests will run in all frameworks
## EasyPost.Integration, EasyPost.Compatibility.VB and EasyPost.Compatibility.FSharp will run only in net7.0
test:
dotnet test

## test-fw - Run the unit tests for a specific framework
## unit-test - Run the unit tests for a specific framework
# @parameters:
# fw= - The framework to build for.
test-fw:
# Note, running .NET Framework tests on a non-Windows machine may cause issues: https://xunit.net/docs/getting-started/netfx/cmdline
dotnet test EasyPost.Tests/EasyPost.Tests.csproj -f ${fw}

.PHONY: help analyze build build-fw build-prod clean coverage coverage-check docs format install-tools install-release-tools install lint lint-scripts prep-release release restore scan setup-win setup-unix test test-fw
unit-test:
dotnet test EasyPost.Tests/EasyPost.Tests.csproj -f ${fw} -c "Debug" # Always run unit tests in Debug mode to allow access to internal members

## integration-test - Run the integration tests for a specific framework
## @parameters:
## fw= - The framework to build for.
integration-test:
dotnet test EasyPost.Integration/EasyPost.Integration.csproj -f ${fw} -c "Release" -restore # Always run integration tests in Release mode to check the end-user experience

## fs-compat-test - Run the F# compatibility tests for a specific framework
## @parameters:
## fw= - The framework to build for.
fs-compat-test:
dotnet test EasyPost.Compatibility.FSharp/EasyPost.Compatibility.FSharp.fsproj -f ${fw} -restore

## vb-compat-test - Run the VB compatibility tests for a specific framework
## @parameters:
## fw= - The framework to build for.
vb-compat-test:
dotnet test EasyPost.Compatibility.VB/EasyPost.Compatibility.VB.vbproj -f ${fw} -restore

.PHONY: help analyze build build-fw build-prod clean coverage coverage-check docs format install-tools install-release-tools install lint lint-scripts prep-release release restore scan setup-win setup-unix test unit-test integration-test fs-compat-test vb-compat-test

0 comments on commit 7ab8d66

Please sign in to comment.