PowerShell: Objekte für Testtoolkit auf 'Geändert' setzen

16. Juni 2016 11:17

Das seit NAV 2016 monatlich mitgelieferte Testtoolkit für automatische Tests
TestToolKit.png

bietet bei der Zusammenstellung der Testcodeunits an, sich nur auf die geänderten Objekte zu beschränken, wenn die Option TCM (Test Coverage Map) in der Testsuite gewählt wurde.
Da die Objekttabelle ja mittlerweile in C/AL nicht mehr geändert werden kann und das manuelle Setzen dieser Haken bei u.U. Hunderten von zu prüfenden Objekten einer Datenbankvorlage sehr zeitraubend ist, ist hier ein Skript, welches diese Arbeit erledigt.
Nach dem Export der zu prüfenden Objekte das Skript laufen lassen und die Objekte mit Eigenschaft 'Modified' re-importieren.
IsModified.png

Danach kann im Testtool die Auswahl der Testcodeunits auf diese direkt eingeschränkt werden.
TestCodeunitsModifiedObjects.png


MSDN-Artikel: How to: Run Automated ApplicationTests

"How Do I"-Videos zum Thema:
https://mbspartner.microsoft.com/NAV/Videos/743
https://mbspartner.microsoft.com/NAV/Videos/744




Code:
       function SetModifiedFlagForAllObjects
        {
        [CmdletBinding()]
        Param
        (
        [String][Parameter(Mandatory=$True)]
        $PathObjectPack
        )
        $argspath = resolve-path $PathObjectPack
        $WorkingFolder = split-path $argspath -Parent
        $ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
        $NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + '_IsModifiedFlag' + (Get-Item $PathObjectPack).Extension
         
        New-Item -Path $WorkingFolder -type directory -Name TempNAVobjects -Force
        $WorkingSubFolder = "$WorkingFolder\TempNAVobjects\"
        remove-item $WorkingSubFolder\*.* -Recurse
        Split-NAVApplicationObjectFile -Source $argspath -Destination $WorkingFolder\TempNAVobjects -PreserveFormatting -Force
       
        foreach ($file in get-ChildItem -Path $WorkingSubFolder\ | Where {$_.extension -eq '.TXT'})
         {
       
              Set-NAVApplicationObjectProperty -Target $file.FullName -modifiedproperty Yes
         
              }

             Write-Host "Deleting old object files…"
             IF (Test-Path $WorkingSubFolder\allobjects.txt) {Remove-Item $WorkingSubFolder\allobjects.txt}
             IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
             IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
             IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
             IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
             IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
             IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
             IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
             
             Write-Host "Joining discrete NAV object files…"
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\TAB*.txt -Destination $WorkingSubFolder\alltables.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\REP*.txt -Destination $WorkingSubFolder\allreports.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\COD*.txt -Destination $WorkingSubFolder\allcodeunits.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\XML*.txt -Destination $WorkingSubFolder\allxmlports.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\MEN*.txt -Destination $WorkingSubFolder\allmenusuites.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\PAG*.txt -Destination $WorkingSubFolder\allpages.txt
             Join-NAVApplicationObjectFile -Source $WorkingSubFolder\QUE*.txt -Destination $WorkingSubFolder\allqueries.txt
             
             Write-Host "Concatenating object files…"
             IF (Test-Path $WorkingSubFolder\alltables.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\alltables.txt)}
              IF (Test-Path $WorkingSubFolder\allreports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allreports.txt)}
             IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allcodeunits.txt)}
              IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allxmlports.txt)}
              IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allmenusuites.txt)}
                IF (Test-Path $WorkingSubFolder\allpages.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allpages.txt)}
             IF (Test-Path $WorkingSubFolder\allqueries.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allqueries.txt)}
             
             IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
             IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
             IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
             IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
             IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
             IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
             IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
             Move-Item $WorkingSubFolder\AllObjects.txt $NewObjectPackFullName  -Force
         
         }


Zum abschließenden Entfernen des Modified-Flags diese Zeile
Code:
Set-NAVApplicationObjectProperty -Target $file.FullName -modifiedproperty Yes

durch diese ersetzen
Code:
Set-NAVApplicationObjectProperty -Target $file.FullName -modifiedproperty No

und den Datei- und Funktionsnamen anpassen:

Code:
           Function DeleteModifiedFlagForAllObjects
            {
            [CmdletBinding()]
            Param
            (
            [String][Parameter(Mandatory=$True)]
            $PathObjectPack
            )
            $argspath = resolve-path $PathObjectPack
            $WorkingFolder = split-path $argspath -Parent
            $ObjectPackFileBaseName = (Get-Item $PathObjectPack).Basename
            $NewObjectPackFullName = (Get-Item $PathObjectPack).DirectoryName + '\' + (Get-Item $PathObjectPack).Basename + '_ModifiedFlagDeleted' + (Get-Item $PathObjectPack).Extension
             
            New-Item -Path $WorkingFolder -type directory -Name TempNAVobjects -Force
            $WorkingSubFolder = "$WorkingFolder\TempNAVobjects\"
            remove-item $WorkingSubFolder\*.* -Recurse
            Split-NAVApplicationObjectFile -Source $argspath -Destination $WorkingFolder\TempNAVobjects -PreserveFormatting -Force
           
            foreach ($file in get-ChildItem -Path $WorkingSubFolder\ | Where {$_.extension -eq '.TXT'})
             {
           
                  Set-NAVApplicationObjectProperty -Target $file.FullName -modifiedproperty No
             
                  }

                 Write-Host "Deleting old object files…"
                 IF (Test-Path $WorkingSubFolder\allobjects.txt) {Remove-Item $WorkingSubFolder\allobjects.txt}
                 IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
                 IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
                 IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
                 IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
                 IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
                 IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
                 IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
                 
                 Write-Host "Joining discrete NAV object files…"
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\TAB*.txt -Destination $WorkingSubFolder\alltables.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\REP*.txt -Destination $WorkingSubFolder\allreports.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\COD*.txt -Destination $WorkingSubFolder\allcodeunits.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\XML*.txt -Destination $WorkingSubFolder\allxmlports.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\MEN*.txt -Destination $WorkingSubFolder\allmenusuites.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\PAG*.txt -Destination $WorkingSubFolder\allpages.txt
                 Join-NAVApplicationObjectFile -Source $WorkingSubFolder\QUE*.txt -Destination $WorkingSubFolder\allqueries.txt
                 
                 Write-Host "Concatenating object files…"
                 IF (Test-Path $WorkingSubFolder\alltables.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\alltables.txt)}
                  IF (Test-Path $WorkingSubFolder\allreports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allreports.txt)}
                 IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allcodeunits.txt)}
                  IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allxmlports.txt)}
                  IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allmenusuites.txt)}
                    IF (Test-Path $WorkingSubFolder\allpages.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allpages.txt)}
                 IF (Test-Path $WorkingSubFolder\allqueries.txt) {Add-Content -path $WorkingSubFolder\AllObjects.txt -value(Get-Content $WorkingSubFolder\allqueries.txt)}
                 
                 IF (Test-Path $WorkingSubFolder\alltables.txt) {Remove-Item $WorkingSubFolder\alltables.txt}
                 IF (Test-Path $WorkingSubFolder\allreports.txt) {Remove-Item $WorkingSubFolder\allreports.txt}
                 IF (Test-Path $WorkingSubFolder\allcodeunits.txt) {Remove-Item $WorkingSubFolder\allcodeunits.txt}
                 IF (Test-Path $WorkingSubFolder\allxmlports.txt) {Remove-Item $WorkingSubFolder\allxmlports.txt}
                 IF (Test-Path $WorkingSubFolder\allmenusuites.txt) {Remove-Item $WorkingSubFolder\allmenusuites.txt}
                 IF (Test-Path $WorkingSubFolder\allpages.txt) {Remove-Item $WorkingSubFolder\allpages.txt}
                 IF (Test-Path $WorkingSubFolder\allqueries.txt) {Remove-Item $WorkingSubFolder\allqueries.txt}
                 Move-Item $WorkingSubFolder\AllObjects.txt $NewObjectPackFullName  -Force
             
             }
Du hast keine ausreichende Berechtigung, um die Dateianhänge dieses Beitrags anzusehen.