StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
72 stars 29 forks source link

Howto run test in VS Code? #690

Open Arthurvdv opened 1 month ago

Arthurvdv commented 1 month ago

image

I'm probably missing something obvious, but how do I execute the test automation in VS Code? Or do I need to install an additional Test extension?

I've created an clean Windows VM with VS Code version v1.91.0 and these installed extensions

I'm also looking into integrating the test in the pipeline of GitHub, running the tests from the command line doesn't return the expected results.

image

dotnet test /p:FeatureFlags=#ManifestHelper

  Determining projects to restore...
  All projects are up-to-date for restore.
  BusinessCentral.LinterCop -> C:\DEMO\BusinessCentral.LinterCop\BusinessCentral.LinterCop\bin\Debug\netstandard2.1\BusinessCentral.LinterCop.dll
  BusinessCentral.LinterCop.Test -> C:\DEMO\BusinessCentral.LinterCop\BusinessCentral.LinterCop.Test\bin\Debug\net8.0\BusinessCentral.LinterCop.Test.dll
Test run for C:\DEMO\BusinessCentral.LinterCop\BusinessCentral.LinterCop.Test\bin\Debug\net8.0\BusinessCentral.LinterCop.Test.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.10.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in C:\DEMO\BusinessCentral.LinterCop\BusinessCentral.LinterCop.Test\bin\Debug\net8.0\BusinessCentral.LinterCop.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

@christophstuber Can you share your setup or do you see anything I'm missing here?

dannoe commented 1 month ago

Currently the references inside the test project are added with the private attribute set to False. So they won't be copied to the bin folder of the test project and the tests fail (but not very visible)

dotnet test doesn't display anything. Rider displays some cryptic messages, and Visual Studio did something similar.

I already commented on the pull request to ask this question (see https://github.com/StefanMaron/BusinessCentral.LinterCop/pull/648#issuecomment-2209548702). But since it's already merged, christophstuber may not have noticed.

<Reference Include="Microsoft.Dynamics.Nav.CodeAnalysis">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>../ALLanguage/extension/bin/Analyzers/Microsoft.Dynamics.Nav.CodeAnalysis.dll</HintPath>
    <Private>False</Private> <!-- should be True, but I am not sure if this was maybe intentional -->
</Reference>

Maybe we can set it to true, until christophstuber gets back to us.

Arthurvdv commented 1 month ago

@dannoe , awesome! That was indeed the difference it seems and now I see the options to run tests as I would expect 🥳

I'll await the feedback of christophstuber before changing these properties in the repo.

image

Last hurdle is to apply the FeatureFlags on executing a test, I'll have a look into that tomorrow.

christophstuber commented 1 month ago

@dannoe Thank you for figuring that out. I'm sorry for being inactive for some time, but I'm currently on a business trip.

dannoe commented 1 month ago

@christophstuber I have another use case for your fork of the RoslyTestKit. Would you be okay with me putting your code into its own repository and releasing a nuget package for it?

christophstuber commented 1 month ago

Created #702 to remove the private false property from the project.

@dannoe Feel free to do so, as long as it remains accessible to everyone. Also maybe mention https://github.com/cezarypiatek/RoslynTestKit as the original source.

Arthurvdv commented 1 month ago

I could use some help getting the tests to run manually in VS Code. Probably it's something simple, but somehow I can't find the right solution 🤔

image

When executing the 'play' button it runs the command dotnet build C:\Users\arthur.vandevondervo\repo\BusinessCentral.LinterCop\BusinessCentral.LinterCop.Test\BusinessCentral.LinterCop.Test.csproj /property:GenerateFullPaths=true /consoleloggerparameters:NoSummary /p:Configuration=Debug /p:Platform="AnyCPU"

Where I somehow want to add an extra parameter for handling the preprocessor directives; /p:FeatureFlags=#Spring2018#Fall2018#Spring2019#Fall2019#Spring2020#Fall2020#Spring2021#Fall2021#Spring2022#Spring2022RV1#Spring2022RV2#Fall2022#Spring2023#Fall2023#Fall2023RV1#Fall2023RV2#Fall2023RV3#Spring2024#Fall2024#Spring2024OrGreater#ManifestHelper#PageSystemAction

Any help on this is appreciated

dannoe commented 1 month ago

As I don't use vscode for C# I can't really help here.

christophstuber commented 1 month ago

What works for me in VS Code is running dotnet test /p:FeatureFlags=#Spring2018#Fall2018#Spring2019#Fall2019#Spring2020#Fall2020#Spring2021#Fall2021#Spring2022#Spring2022RV1#Spring2022RV2#Fall2022#Spring2023#Fall2023#Fall2023RV1#Fall2023RV2#Fall2023RV3#Spring2024#Fall2024#Spring2024OrGreater#ManifestHelper#PageSystemAction from the terminal.

Arthurvdv commented 1 month ago

@dannoe and @christophstuber, thank both of you for the quick response!

The command-line approach indeed works 🤗 I was hoping to have it working with the gui and with debugging functionality, but that will be for somewhere in the future I guess.