Book a Demo

Author Topic: Automated Testing  (Read 7334 times)

mogra69

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Automated Testing
« on: January 08, 2007, 09:12:50 am »
I have a EA AddIn. I want to build automated tests for the AddIn.

Any thoughts on how this can be accomplished?

Can NUnit be used? How about SilkTest?

Please share your thoughts and experiences. I am sure this is a topic of wide interest.
« Last Edit: January 08, 2007, 09:13:13 am by mogra69 »

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Automated Testing
« Reply #1 on: January 08, 2007, 01:05:36 pm »
If you're addin is .Net you should be able to use nUnit.  If it's Java you should be able to use JUnit.  I'm not sure about SilkTest, but I don't see a reason that as long as the testing framework can be used with the language/framework your addin is written in you shouldn't be able to use it.

bittercoder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
  • .Net developer
    • View Profile
Re: Automated Testing
« Reply #2 on: January 08, 2007, 02:10:32 pm »
I've done quite a bit of automated testing with a particular EA Addin I'm developing - we're just using NUnit and a mocking framework (RhinoMocks - http://www.ayende.com/projects/rhino-mocks.aspx) to mock out the EA.Repository interface and collections etc.

Let me know if you need any more pointers.

mogra69

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Automated Testing
« Reply #3 on: January 09, 2007, 11:50:03 am »
Thanks for your response. I will investigate NMock and RhinoMock.

mogra69

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Automated Testing
« Reply #4 on: January 09, 2007, 06:06:28 pm »

For any serious AddIn testing the Repository has to be created for NMock.

Say for example we AddIn access Repository.Models collection. How do we create the collection for NMock testing? The problem I see is that EA.CollectionClass does not have a public constructor.

The following code does not compile:

EA.Collection models = new EA.CollectionClass;

You mention testing collections earlier. Please let me know how you did it.

Thanks.

bittercoder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
  • .Net developer
    • View Profile
Re: Automated Testing
« Reply #5 on: January 09, 2007, 06:49:01 pm »
You have to create a mock collection (you don't want to use the COM classes themselves, but the interfaces) ... so say for Rhino Mocks (I dont really like NMock, bit clunky, but the ideas are the same) you could implement a test fixture which creates the scenario of:


[*] Having the repository return a models collection.
[*] Invoking the AddNew method on the models collection.
[*] Having a new package returned.
[*] Verifying that the name for this package is the one we expected.
[/list]

Here's the code for this example test fixture:

[Test]
public void MockRepositoryModelsCollectionAndPackage()
{
   MockRepository mockRepository = new MockRepository();

   string expectedName = "My Package";
   string expectedType = "Package";

   EA.Package package = mockRepository.CreateMock<EA.Package>();
   Expect.Call(package.Name).Return(expectedName);

   EA.Collection collection = mockRepository.CreateMock<EA.Collection>();
   Expect.Call(collection.AddNew(expectedName, expectedType)).Constraints(Is.Equal(expectedName),
                                                                   Is.Equal(expectedType)).Return(
       package);

   EA.Repository repository = mockRepository.CreateMock<EA.Repository>();
   Expect.Call(repository.Models).Return(collection);

   mockRepository.ReplayAll();

   EA.Package newPackage = repository.Models.AddNew(expectedName, expectedType) as EA.Package;
   Assert.AreEqual(expectedName, newPackage.Name);

   mockRepository.VerifyAll();
}

And anywhere that you need a really "smart" mock object (probably a bad smell in your test case if it's complex - but it does happen on occasion) then just implement your own class using the EA.XXXXX interface you need - of course then you have to implement the whole thing, which could be trouble then it's worth :)

Let me know if you need any more pointers on Mocking this stuff.

Cheers,

-  Alex

mogra69

  • EA User
  • **
  • Posts: 21
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Automated Testing
« Reply #6 on: January 09, 2007, 07:10:24 pm »
This is good stuff. Thanks a lot for your help.

Just curious... could you briefly describe the AddIn's capabilities that you tested using mock.

Thanks.

bittercoder

  • EA User
  • **
  • Posts: 30
  • Karma: +0/-0
  • .Net developer
    • View Profile
Re: Automated Testing
« Reply #7 on: January 09, 2007, 07:21:20 pm »
We've mostly tested creating "aggregate" elements (Elements, containing child elements and so on) and reading them back...     Mostly to ensure we have a suite of regression tests as we add new features to the Addin.

I can't really say much about the Addin itself, I'm under NDA until the product goes "public".

Cheers,

- Alex

Charlie

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
  • I love YaBB 1G - SP1!
    • View Profile
Re: Automated Testing
« Reply #8 on: June 11, 2007, 03:52:48 am »
I am trying to do the following:

- Create an instance of a test EA.Repository with child elements, packages, diagrams, etc.
- I want to avoid calling the OpenFile method of the repository so that my tests can run on our continuous integration server independent of file system parameters.

Can this be done using a Mock objects? I am struggling to do this with RhinoMocks.  If it is possible, can you post some sample code?