Author Topic: Import/Export of tests using 'CSV Import/Export'  (Read 1752 times)

Dan

  • EA Novice
  • *
  • Posts: 4
  • Karma: +0/-0
  • I love YaBB 1 Gold!
    • View Profile
Import/Export of tests using 'CSV Import/Export'
« on: July 29, 2003, 04:15:41 am »
Hi All

I would be nice if it was posibile to import/export tests in CSV format. This would be helpful in the following situation: lets say a tester which doesn't have a license of EA runs a series of tests generated from the EA in an word document format. Updates the word document with the new results of each test. Then she wants to import into EA the entire document.

I tried to do this by first transforming the word document into a csv format and import this format into EA. However, EA doesn't allow me to create import specifications with customised columns. And, worse, it doesn't have the facility to import tests from cvs files (or any other format).

Rgds
Dan

mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
Re: Import/Export of tests using 'CSV Import/Expor
« Reply #1 on: July 29, 2003, 08:14:41 am »
I suggest you write a word macro that does this through the automation interface. If you are already a programmer, that is not too difficult. And it might save you the bother of converting your document to CSV each time.
I am using a word macro to do the opposite - that is generate test descriptions in word format from EA (because I didn't like the standard output format).

Mikkel

jdrerup

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Import/Export of tests using 'CSV Import/Expor
« Reply #2 on: August 06, 2003, 01:19:07 am »
Hi, would you be prepared to share the work you have done with Word Automation?

There are a lot of us out there who would benefit from seeing the automation work that some gurus/wizards like you have done.

I've had a go at doing something like this myself without much luck...

It would also be great if Sparx setup a repository or another discussion thread dedicated to Automation so that it was easy to share the work we have all done.

I have started exposing a lot of the information in a project as Web Services (still in Beta) so that we can easily disseminate it around the company/team.

I have found that the businesses I work with are very keen on using EA but the MAJOR hinderance is still the work required to output 'Client Facing' documents easily and quickly from EA.

If I were able to get around this problem then the adoption rate and support for EA is likely to increase dramatically.

mbc

  • EA User
  • **
  • Posts: 237
  • Karma: +1/-0
  • Embedded software developer
    • View Profile
Re: Import/Export of tests using 'CSV Import/Expor
« Reply #3 on: August 06, 2003, 02:18:52 am »
Here is a large chunk of code for you. It is pretty quick-and-dirty programming that I did in order to get some nice system test documentation out quickly.

Sorry that I don't have the time to document it nicely for you, but I can tell you that:

1. GenerateTestDescriptions is the macro that I call to start it all. It searches for a bookmark in the Word document and inserts the test descriptions in that place (replacing old test descriptions).

2. ListUseCasesWithoutTests is another macro. It is a utility to make a list of use cases that still need tests to be written. Just a tool for the software designer.

3. It is written for a specific EA model and will probably not work without modifications on other models.


I hope you find this helpful. As to a sharing forum, I don't think I will be sharing heaps of more code in the future, since I consider that producing this sort of thing is the way I make my living. I can't give it all away for free. ;) But I will certainly be glad to give advice and code snippets.

Mikkel

Code: [Select]

Public Enum eFindMode
   fmElementsWithoutTests
End Enum
Public m_Repository As Object
Public ListOfTests As New Collection

Sub GenerateTestDescriptions()
   
   If ActiveDocument.Bookmarks.Exists("SystemTests") = True Then
       ActiveDocument.Bookmarks("SystemTests").Select
       
       ''clear old text
       
       Selection.Text = " "
       ActiveDocument.Bookmarks.Add "SystemTests", Selection.Range
       Selection.Collapse wdCollapseStart
       
       ''create the repository object
       Set m_Repository = CreateObject("EA.Repository")
       
       ''open an EAP file
       m_Repository.OpenFile ("C:\Data\MyModel.EAP")
       
       IterateViews
       DocumentTests
       For idx = 1 To ListOfTests.Count
           ListOfTests.Remove 1
       Next
       
       ''close the repository and tidy up
       m_Repository.Exit
       Set m_Repository = Nothing
   
   Else
       MsgBox "Bookmark ""SystemTests"" must be defined"
   End If
   
End Sub


Sub IterateTests(aElement As Variant)
   Dim Testidx As Integer
   Dim Listidx As Integer
   Dim aTest As Object
   Dim TempString As String
   
   For Testidx = 0 To aElement.Tests.Count - 1
       
       Set aTest = Nothing
       Set aTest = aElement.Tests.GetAt(Testidx)
       TestNameArray = Split(aTest.Name, " ", 4)
       If aTest.Type <> "System" Then
           If ListOfTests.Count = 0 Then
               ListOfTests.Add aTest, aTest.Name
           Else
               For Listidx = 1 To ListOfTests.Count
                   TempString = ListOfTests(Listidx).Name
                   ListNameArray = Split(TempString, " ", 4)
                   listno = CInt(CStr(ListNameArray(2)))
                   testno = CInt(CStr(TestNameArray(2)))
                   If listno >= testno Then
                       ListOfTests.Add aTest, aTest.Name, Listidx
                       Exit For
                   Else
                       If Listidx = ListOfTests.Count Then
                           ListOfTests.Add aTest, aTest.Name
                           Exit For
                       End If
                   End If
               Next
           End If
       End If
   Next
   Set aTest = Nothing
End Sub


Sub DocumentTests()
   Dim idx As Integer
   For idx = 1 To ListOfTests.Count
       Set aTest = ListOfTests(idx)
       
       Selection.InsertAfter (aTest.Name)
       Selection.Paragraphs.Style = wdStyleHeading2
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
               
       Selection.InsertAfter ("Test Procedure")
       Selection.Paragraphs.Style = "Heading 3"
       Selection.Paragraphs.SpaceAfter = 12
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
               
       Selection.InsertAfter (aTest.Notes)
       Selection.Paragraphs.Style = "Normal List"
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
       
       Selection.InsertAfter ("Preconditions")
       Selection.Paragraphs.Style = wdStyleHeading3
       Selection.Paragraphs.SpaceAfter = 12
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
       
       Selection.InsertAfter (aTest.Input)
       Selection.Paragraphs.Style = "Normal List"
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
       
       Selection.InsertAfter ("Acceptance Criteria")
       Selection.Paragraphs.Style = wdStyleHeading3
       Selection.Paragraphs.SpaceAfter = 12
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
     
       Selection.InsertAfter (aTest.AcceptanceCriteria)
       Selection.Paragraphs.Style = "Normal List"
       Selection.InsertParagraphAfter
       Selection.Collapse Direction:=wdCollapseEnd
   Next
   Set aTest = Nothing
       
End Sub


Sub IterateElements(aPackage As Variant)
   Dim idx As Integer
   For idx = 0 To aPackage.Elements.Count - 1
       Selection.Collapse Direction:=wdCollapseEnd
       Set aElement = aPackage.Elements.GetAt(idx)
       If aElement.Type <> "Boundary" Then
           IterateTests aElement
       End If
   Next
End Sub


Sub IteratePackages(aView As Variant)
   Dim idx As Integer
   For idx = 0 To aView.Packages.Count - 1
       Set aPackage = aView.Packages.GetAt(idx)
       IterateElements aPackage
   Next
End Sub

Sub IterateViews()
   Dim idx As Integer
   Set aModel = m_Repository.Models.GetAt(0)
   For idx = 0 To aModel.Packages.Count - 1
       Set aView = aModel.Packages.GetAt(idx)
       If aView.Name = "Use Case Model" Then
           IteratePackages aView
       End If
   Next
End Sub


Sub FindIteratePackages(Mode As eFindMode, ParentPackage As Variant)
   Dim idx As Integer
   For idx = 0 To ParentPackage.Packages.Count - 1
       Set Package = ParentPackage.Packages.GetAt(idx)
       If TestPackage(Mode, Package) Then
           DoPackageAction Mode, Package
           FindIterateElements Mode, Package
           FindIteratePackages Mode, Package
       End If
   Next
End Sub
Sub FindIterateElements(Mode As eFindMode, ParentPackage As Variant)
   Dim idx As Integer
   For idx = 0 To ParentPackage.Elements.Count - 1
       Set Element = ParentPackage.Elements.GetAt(idx)
       If TestElement(Mode, ParentPackage, Element) Then
           DoElementAction Mode, ParentPackage, Element
       End If
   Next
End Sub

Function TestPackage(Mode As eFindMode, Package As Variant) As Boolean
   Dim Result As Boolean
   
   Select Case Mode
   Case eElementsWithoutTests
       Result = True
   End Select
   
   TestPackage = Result
End Function
Sub DoPackageAction(Mode As eFindMode, Package As Variant)
   Select Case Mode
   
   Case eElementsWithoutTests
   End Select

End Sub
Function TestElement(Mode As eFindMode, Package As Variant, Element As Variant) As Boolean
   Dim Result As Boolean
   
   Select Case Mode
   Case eElementsWithoutTests
       If (Element.Type = "UseCase") And (Element.Tests.Count = 0) Then
           Result = True
       Else
           Result = False
       End If
   End Select
   
   TestElement = Result
End Function
Sub DoElementAction(Mode As eFindMode, Package As Variant, Element As Variant)
   Select Case Mode
   
   Case eElementsWithoutTests
       Selection.InsertAfter Element.Name & " " & Chr(9) & "(" & Package.Name & ")"
       Selection.InsertParagraphAfter
   End Select

End Sub
Function OpenModel(FileName As String) As Variant

   ''create the repository object
   Set m_Repository = CreateObject("EA.Repository")
   
   ''open an EAP file
   m_Repository.OpenFile (FileName)
   
   Set Model = m_Repository.Models.GetAt(0)
   
   Set OpenModel = Model
End Function
Sub CloseModel()
   m_Repository.Exit
   Set m_Repository = Nothing
End Sub

Sub ListUseCasesWithoutTests()
   Dim idx As Integer
   Set Model = OpenModel("C:\Data\MyModel.EAP")
   
   For idx = 0 To Model.Packages.Count - 1
       Set Package = Model.Packages.GetAt(idx)
       If Package.Name = "Use Case Model" Then
           FindIteratePackages fmElementsWithoutTests, Package
       End If
   Next
   
   CloseModel
End Sub