Last active
April 29, 2019 16:36
-
-
Save jimmymcp/7ac309d79acd48a3ac76b1666d2e7b31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
codeunit 90100 "Automated Test Mgt. BHTMN" | |
{ | |
var | |
CALTestManagement: Codeunit "CAL Test Management"; | |
ObjectNotCompiledErr: Label 'Object not compiled.'; | |
procedure GetTests(TestSuiteName: Code[10]; StartID: Integer; EndID: Integer) | |
var | |
CALTestSuite: Record "CAL Test Suite"; | |
CALTestLine: Record "CAL Test Line"; | |
AllObjWithCaption: Record AllObjWithCaption; | |
begin | |
GlobalLanguage(1033); | |
if TestSuiteName = '' then | |
TestSuiteName := 'DEFAULT'; | |
if not CALTestSuite.Get(TestSuiteName) then begin | |
CALTestSuite.Init(); | |
CALTestSuite.Name := TestSuiteName; | |
CALTestSuite.Description := 'Automated Testing'; | |
CALTestSuite.Validate(Export, false); | |
CALTestSuite.Insert(true); | |
end; | |
CALTestSuite.SetRecFilter(); | |
if StartID = 0 then | |
StartID := 9000000; | |
//add test codeunits | |
AllObjWithCaption.SetRange("Object Type", AllObjWithCaption."Object Type"::Codeunit); | |
AllObjWithCaption.SetRange("Object Subtype", 'Test'); | |
if EndID > 0 then | |
AllObjWithCaption.SetRange("Object ID",StartID,EndID) | |
else | |
AllObjWithCaption.SetFilter("Object ID",'%1..',StartID); | |
AddTestCodeunits(CALTestSuite, AllObjWithCaption); | |
//add test methods | |
CALTestLine.SetRange("Test Suite", TestSuiteName); | |
CALTestLine.SetRange("Line Type", CALTestLine."Line Type"::Codeunit); | |
if CALTestLine.FindSet() then | |
repeat | |
CALTestManagement.RunSuite(CALTestLine, false); | |
until CALTestLine.Next() = 0; | |
CALTestLine.SetRange("Line Type"); | |
if CALTestLine.FindFirst() then; | |
end; | |
procedure ClearTestSuite(TestSuite: Code[10]) | |
var | |
CALTestLine: Record "CAL Test Line"; | |
begin | |
CALTestLine.SetRange("Test Suite",TestSuite); | |
CALTestLine.DeleteAll(true); | |
end; | |
local procedure AddTestCodeunits(CALTestSuite: Record "CAL Test Suite"; VAR AllObjWithCaption: Record AllObjWithCaption) | |
var | |
TestLineNo: Integer; | |
begin | |
if AllObjWithCaption.FIND('-') then begin | |
TestLineNo := GetLastTestLineNo(CALTestSuite.Name); | |
repeat | |
TestLineNo := TestLineNo + 10000; | |
AddTestLine(CALTestSuite.Name, AllObjWithCaption."Object ID", TestLineNo); | |
until AllObjWithCaption.Next() = 0; | |
end; | |
end; | |
local procedure GetLastTestLineNo(TestSuiteName: Code[10]) LineNo: Integer | |
var | |
CALTestLine: Record "CAL Test Line"; | |
begin | |
CALTestLine.SetRange("Test Suite", TestSuiteName); | |
if CALTestLine.FindLast() then | |
LineNo := CALTestLine."Line No."; | |
end; | |
local procedure AddTestLine(TestSuiteName: Code[10]; TestCodeunitId: Integer; LineNo: Integer) | |
var | |
CALTestLine: Record "CAL Test Line"; | |
AllObj: Record AllObj; | |
Object: Record Object; | |
CodeunitIsValid: Boolean; | |
begin | |
with CALTestLine DO begin | |
if TestLineExists(TestSuiteName, TestCodeunitId) then | |
exit; | |
Init(); | |
Validate("Test Suite", TestSuiteName); | |
Validate("Line No.", LineNo); | |
Validate("Line Type", "Line Type"::Codeunit); | |
Validate("Test Codeunit", TestCodeunitId); | |
Validate(Run, true); | |
Insert(true); | |
AllObj.SetRange("Object Type", AllObj."Object Type"::Codeunit); | |
AllObj.SetRange("Object ID", TestCodeunitId); | |
AllObj.FindFirst(); | |
if Format(AllObj."App Package ID") <> '' then | |
CodeunitIsValid := true; | |
if not CodeunitIsValid then begin | |
Object.SetRange(Type, Object.Type::Codeunit); | |
Object.SetRange(ID, TestCodeunitId); | |
CodeunitIsValid := Object.FindFirst(); | |
end; | |
if CodeunitIsValid then begin | |
CALTestManagement.SETPUBLISHMODE(); | |
SetRecFilter(); | |
Codeunit.Run(Codeunit::"CAL Test Runner", CALTestLine); | |
end else begin | |
Validate(Result, Result::Failure); | |
Validate("First Error", ObjectNotCompiledErr); | |
Modify(true); | |
end; | |
end; | |
end; | |
local procedure TestLineExists(TestSuiteName: Code[10]; TestCodeunitId: Integer): Boolean | |
var | |
CALTestLine: Record "CAL Test Line"; | |
begin | |
CALTestLine.SetRange("Test Suite", TestSuiteName); | |
CALTestLine.SetRange("Test Codeunit", TestCodeunitId); | |
exit(not CALTestLine.IsEmpty()); | |
end; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-TestCodeunitsInContainer { | |
param ( | |
# Container to load test codeunits into | |
[Parameter(Mandatory=$false)] | |
[string] | |
$ContainerName = (Get-ContainerFromLaunchJson), | |
# Credentials to use to connect to web service | |
[Parameter(Mandatory=$false)] | |
[PSCredential] | |
$Credential = (New-CredentialFromEnvironmentJson), | |
# Name of the test suite to add the test codeunits to | |
[Parameter(Mandatory=$false)] | |
[string] | |
$TestSuite = '', | |
# Start of the range of objects to add | |
[Parameter(Mandatory=$false)] | |
[int] | |
$StartId = ((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'idrange').from), | |
# End of the range of objects to add | |
[Parameter(Mandatory=$false)] | |
[int] | |
$EndId = ((Get-AppKeyValue -SourcePath (Get-Location) -KeyName 'idrange').to) | |
) | |
Install-BuildHelper -ContainerName $ContainerName | |
$CompanyName = Get-ContainerCompanyToTest -ContainerName $ContainerName | |
$Url = "http://{0}:7047/NAV/WS/{1}/Codeunit/AutomatedTestMgt" -f (Get-NavContainerIpAddress -containerName $ContainerName), $CompanyName | |
Write-Host "Calling $Url to retrieve test codeunits" | |
$AutomatedTestMgt = New-WebServiceProxy -Uri $Url -Credential $Credential | |
$AutomatedTestMgt.GetTests($TestSuite,$StartId,$EndId) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment