Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Unit testing with Revit API

  1. #1
    100 Club
    Join Date
    2007-10
    Location
    Brisbane
    Posts
    138
    Login to Give a bone
    0

    Default Unit testing with Revit API

    I've recently discovered the glory of unit testing...

    My excuse for not doing it has always been that its too hard with the revit API. I'm wondering is there any methods anyone is using for doing this? Surely my unit tests could run from within revit as well.. I'd have to open a document, and then run the unit tests I guess.

    I could manually make my own, but is there a way to use nUnit or something similar from within the revit API?

  2. #2
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Fantastic tool for TDD isn't it? I use it every day. Personally don't use nUnit but it is a vital tool for API development and code documentation. Also try one of the mocking frameworks. This can be useful especially for early UI development if you are using a MVC design.

    It's very hard for a number of reasons, the data is dynamic, the build/test/build cycle is non existent except in VSTA.

    Not sure what you mean by manually making your own? It certainly would be very useful to be able to unit test in Revit wouldn't it...

    Guy

  3. #3
    100 Club
    Join Date
    2004-02
    Location
    Brookline, MA
    Posts
    186
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    I couldn't agree more!

    We've done it sometimes in AutoCAD, when you could connect to AutoCAD and kick things off via COM.

    I suspect that it's do-able via some kind of customization to NUnit or the VS2008 Test infrastructure - I just haven't had the time to chase it yet.

    I'd imagine we'd need to define a Test Project ExternalCommand - then see if we could customize the behavior from there (or worse-comes-to-worst, just use reflection and DIY - as Rod mentioned).

    -Matt

  4. #4
    100 Club
    Join Date
    2004-02
    Location
    Brookline, MA
    Posts
    186
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    By the way - what unit testing framework do you guys prefer? NUnit?

    I've used NUnit and MSTest a lot - and I've been meaning to look at xUnit.NET...

    Just wondering if all of us use the same, so if one of us does have the chance to invent something, the others might share

    -Matt

  5. #5
    AUGI Addict
    Join Date
    2003-11
    Location
    New Zealand
    Posts
    1,116
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Quote Originally Posted by mmason.65315 View Post
    I'd imagine we'd need to define a Test Project ExternalCommand - then see if we could customize the behavior from there (or worse-comes-to-worst, just use reflection and DIY - as Rod mentioned).-Matt
    If you want to use a unit testing for more than just testing libraries and do more TDD then you need a Build-Test-Build cycle or it's a waste of time. This is difficult on many levels. It's a hell of a lot of work regardless of which testing framework you choose. As a hint, I'd strongly recommend you don't roll your own testing framework and reflection is NOT your friend

    Guy

  6. #6
    Member
    Join Date
    2008-09
    Location
    Atlanta, GA
    Posts
    19
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Quote Originally Posted by mmason.65315 View Post
    By the way - what unit testing framework do you guys prefer? NUnit?
    NUnit has come through for me on many a occassions. I like it better than Microsoft's testing framework.

    Also I am hoping Autodesk guys will remove the GUI dependancy from the API sooner and life will be much better !

    Prashant

  7. #7
    Member
    Join Date
    2008-09
    Location
    Atlanta, GA
    Posts
    19
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Quote Originally Posted by r.howarth View Post
    I've recently discovered the glory of unit testing...
    welcome to the club !

    Quote Originally Posted by r.howarth View Post
    My excuse for not doing it has always been that its too hard with the revit API. I'm wondering is there any methods anyone is using for doing this?
    I agree with the hard to do with revit API part. My external commands usually just instantiate the objects in my application and hand over the data. Everything after that can be tested easily. Needless to say, I have my tests restricted to the functionality past the invoking of externalcommand. I kinda know what data I would want from the document and may have to create some for testing purposes.

    My applications mostly read from the document and rarely push/move anything geometrically.

    I would like to hear what you guys do!

    Prashant

  8. #8
    100 Club
    Join Date
    2007-10
    Location
    Brisbane
    Posts
    138
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Quote Originally Posted by ppathak View Post
    welcome to the club !



    I agree with the hard to do with revit API part. My external commands usually just instantiate the objects in my application and hand over the data. Everything after that can be tested easily. Needless to say, I have my tests restricted to the functionality past the invoking of externalcommand. I kinda know what data I would want from the document and may have to create some for testing purposes.

    My applications mostly read from the document and rarely push/move anything geometrically.

    I would like to hear what you guys do!

    Prashant
    Yeah that's probably the best option, most of my commands so far haven't been all that complex if you removed classes that are tightly coupled with the commandData though.

    I've started using NUnit with Resharper(for in-Gui test window) on non-revit ASP.Net project I'm working on and love it.

    What I was originally thinking in my initial post was to have the tests for my particular command running from inside revit, ie i start up a revit document and then run a macro which runs the tests, but theere'd be problems with the state of the commanddata object changing and it would be a pain to get working if its even possible.

  9. #9
    100 Club
    Join Date
    2004-02
    Location
    Brookline, MA
    Posts
    186
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    I poked at it for a little bit last week, and made a bit of progress (having an ExternalCommand that runs the NUnit GUI - open source can be handy).

    My next step though was to write an Extension class to implement a "RevitTest" - where the test method could have a signature which handed you the commandData object for your test (as well as doing various transactions, etc).

    There are also a bunch of nasty issues with AppDomains and such, which I've worked around rather than resolved so far.

    I'm not sure when I'll have time to take it further, though...

    -Matt

  10. #10
    Member
    Join Date
    2010-10
    Posts
    17
    Login to Give a bone
    0

    Default Re: Unit testing with Revit API

    Any further efforts on this front? Would like to be able to do this.

    Sounds like what you're talking about would involve invoking the tests from within Revit? Or could Revit tests be initiated from outside?

Page 1 of 2 12 LastLast

Similar Threads

  1. Unit Precision in Revit
    By rdaniel in forum Revit Architecture - General
    Replies: 7
    Last Post: 2011-03-28, 02:40 PM
  2. After install imperial unit template, library and want to add metric unit
    By 01chang in forum Revit Architecture - General
    Replies: 0
    Last Post: 2009-12-03, 09:14 PM
  3. Alpha/Beta testing of Imperial unit version of AutoCAD Structural Detailing
    By wai.chu in forum AutoCAD Structural Detailing
    Replies: 0
    Last Post: 2008-07-16, 09:04 PM
  4. Testing: Revit + Viz + Vray
    By christopher.zoog51272 in forum Revit - Gallery
    Replies: 28
    Last Post: 2004-10-23, 06:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •