jimmymcp / al-test-runner

VS Code Extension to help run AL tests against Business Central container
https://jpearson.blog/al-test-runner-for-visual-studio-code/
MIT License
12 stars 16 forks source link

No output from the test execution #57

Open ricardopaiva opened 2 years ago

ricardopaiva commented 2 years ago

Hi, I'm trying to setup and use the AL Test Runner but I'm unable to get any output from the test execution. What I'm using:

  1. A BC 19.2 instance running on Docker;
  2. Latest BCContainerHelper installed;
  3. Latest AL Test Runner app;

What I've done:

  1. I've installed the AL Test Runner Service and the OData service seems to be exposed;
  2. Setup the config.json file to run tests on the local Docker container

What I get: When I try to run a test from the Test Explorer, I get the following on the Terminal:

image

I've tried to manually run the Invoke-TestRunnerService.ps1 script and debug it and here's where it stops:

image

You can see that there's no message in the error so I get no output on the Terminal:

image

I was not able to understand why the Invoke-WebRequest is failing.

I have debug the AL Test Runner Service and the TestRunner codeunit (codeunit 79151 "Test Runner JP") is being called but I guess that some error is being retrieved, I just cannot find it. On the OnAfterTestRun trigger, the Success parameter is False but GetLastErrorText() and GetLastErrorCallStack() returns no error.

I couldn't find any related error in the container Event Viewer log.

Any hint?

jimmymcp commented 2 years ago

Hi, some ideas:

It sounds like you're all setup OK, just trying to get some more info.

ricardopaiva commented 2 years ago

Thanks. In the meanwhile i just noticed that i forgot to key in the TestSuiteName in the config.json file but after i did it i get the same behavior. I will do some more testing, based on your inputs/questions and i will let you know.

ricardopaiva commented 2 years ago

It seems like I was able to make it work by doing a change on the Test-Runner-Service app. On the Service.codeunit.al file:

trigger OnAfterTestRun(CodeunitId: Integer; CodeunitName: Text; FunctionName: Text; Permissions: TestPermissions; Success: Boolean)
begin
    if (FunctionName = '') then
        exit;

    if not Success then begin
        Error(GetLastErrorText() + '\ \' + GetLastErrorCallStack());
    end;
end;

If seems like the FunctionName parameter when the OnAfterTestRun is being called for the first time is empty and the Success parameter is false, so an error is being retrieved all the time. I couldn't understand why this is happening. I thought it was because of the OnRun trigger on the test codeunit but after removing it the behavior was still the same.

Does this make sense to you?

CPSTOS commented 1 year ago

Hey, I'm facing a similar problem with that piece of code. I'm trying to debug a test and the debugger won't hit any breakpoint in my test. It does stop on breakpoints in "Test Runner Service JP" though. After the failing test hits "OnAfterTestRun" th error is not being collected, since FunctionName is empty and TestName is the current tests name:

`trigger OnAfterTestRun(CodeunitId: Integer; CodeunitName: Text; FunctionName: Text; Permissions: TestPermissions; Success: Boolean) begin if not Success then if (TestCodeunitId = CodeunitId) and (FunctionName = TestName) then Error(GetLastErrorText() + GetLastErrorCallStack());

    if not Success then
        FailedTests += 1;
end;`

Also I get "Exception of type 'Microsoft.Dynamics.Nav.Types.Exceptions.NavNCLDialogException' was thrown." in the Terminal which I can not get further details on. Not in the event log, nor via application insights.

Any idea what is keeping me from attaching the debugger to the test of choice?

Best regards

Sven

CPSTOS commented 1 year ago

Is it a timing issue, because the next session actually is the test runner, which uses new sessions for each test, so those are not in scope?

jimmymcp commented 1 year ago

Do you see any difference if you attach the debugger yourself before debugging the test? (as opposed to the extension attaching the debugger)