Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Unit Testing

New Here ,
Mar 25, 2008 Mar 25, 2008
Hi,

I followed the procedure described here http://www.adobeforums.com/webx/.3bbe2c4c to introduce a unit testing class into my plug-In .. now in InDesign debug I get my unit testing menu item in "Test->Unit Test", but when I attempt to run the test I get:

ASSERT 'entry.test != nil' in c:\development\cobalt\source\private\debugging\UnitTestList.cpp at line 254 failed.
c:\development\cobalt\source\private\debugging\UnitTestList.cpp (254)

with "Running TestCaseOne...passed" in the Debug Log, but none of my tests actually run...

Any reason why I could be getting this assert?

Thanks!
TOPICS
SDK
1.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 26, 2008 Mar 26, 2008
I think the unit test code that actually execute each test is not in the build anymore.

-lee
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2008 Mar 27, 2008
Lee,

How would I go about unit testing in my plug-Ins then? What's the classical way of doing it?

Thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2008 Mar 27, 2008
I don't have too much insight on that either, so someone can chime in if they know. But I think in essence, unit test is a way to exercise your code by providing some pre-determined parameters. So for example, if you have a function foo takes a boolean as input, then you might have a unit test case that will call foo twice, one with input true, the other time with false. Then you will need to have a unit test manager or something that will call all the test cases to exercise your code. Back to the foo case, by calling it twice with different parameters, hopefully it will cover all the code paths in your foo function. This way, say there is some API used in foo whose functionality has changed over time, it will probably cause your foo to fail, then by unit test the case for foo, you will catch that.

So I guess you need to implement some sort of framework that can visit all the test case, and maybe gather test result and report result. Then the client of of the unit testing needs to come up with test case that's gotten called by the framework, and the test case should execute the code paths you wish to test.

Regards,
lee
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 27, 2008 Mar 27, 2008
Lee,

Thanks for the explanation about Unit testing, it was really helpful. But my original concern is about a framework that provides unit testing facilities for you like JUnit in Java. I'm just wondering what everyone uses for unit testing in the Adobe framework... what's the classical way of testing your plug-ins and so on... tried to use this embedded CUnitTest class that InDesign provides but it seems as you said it's not available in the build anymore...

Thanks
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 18, 2008 Sep 18, 2008
Hi miGZy and Lee,

Say about Unit test for Plug-in, I've currently write some unit test for my plug-in is writen for Adobe InDesign CS3, using JsAssertion as a Unit test framework, you know, the Adobe plug-in code have used the Adobe Extend Script, so it required to run with the Adobe Extend Script runtime. That's mean the Plug-in code depend on Adobe Environment. So, my question is how could we run unit test for Adobe Javascript without run Adobe Indesign Environment or do we have any ways just to load the Adobe InDesign runtime to provide all objects model enable run plug-in code and unit test for it?

Thanks for review my question.

Khoa Duong
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
I would be interested in seeing that original procedure you describe to get a unit test into a plug-in but that link doesn't seem to work for me. Are you sure it's correct?

I've put some unit tests in place for our plugins but only for extracted classes which can be run outside of the Adobe framework.

There are a few solutions for running unit tests on plug-in code but none of them lightweight.

Theoretically it would be possible to build a set of mock classes to imitate the ID class framework but that's a big task for little gain.

Another way would be to create class wrappers for the calls to ID SDK so that you can replace them for sensing when you run the unit tests.

Finally, a suggestion which I had from inside Adobe but which I haven't tried.. Adapt Snippet runner to load, init and unload your unit tests dynamically. That would rely on having InDesign permanently running. You would only be able load code snippets which do not alter the object model since the object model is set in stone at startup. This approach would mean separating code which alters the OM to run in plugin at application startup and action code which you could compile and test in snippet dlls.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
Thanks for your reply Caerwyn, however, I'm another guys, and i did not post the original topic, I've just raise one more my solution for Unit test in Plug-in. I'm wondering whether we could import the Action script object model into unit test code and run test for Plug-in code independently with Adobe Indesign Environment? Or could we load or stimulate a Adobe Indesign Environment (with all object models will be load in memory but without run Adobe Indesign Application)? Because I would like to have an automation unit test and we don't want for each time to load test we must load InDesign first.

Thanks

Khoa Duong
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
Hi Khoa,

No worries, I just replied to the discussion and hoped the right guy picked it up.

I'm not sure I can shed any light on your problems, our plugins are in C++ so the problem of extracting classes and running them outside of the Adobe environment is plausible.

For what it's worth...

I've avoided mocking up the InDesign API and I believe that's what led the Adobe developer I spoke with to suggest using Snippet runner. I think neither are ideal for unit tests, which after all should be small, pointed, rapid and modular.

As for loading InDesign each time. I agree with you completely. Unit test load and run time should be counted in milliseconds not minutes ;-)

Your plug-ins are written using JavaScript, aren't they? Is it not possible to extract the javascript which can be run outside of InDesign and put that under unit test? That may allow you to at least "sense" whether the calls into the InDesign API to report back in the tests.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
Right Caerwyn, the plug-ins are written by javascript, I think it's unable extract the plug-in code, because in our code, we've currently used some Adobe Core Javascript Classes which it's will be throw an runtime error when run the code outside Adobe Environment, I've tried it for example, using File or Folder objects (Adobe Extend script object model), load the script test on JsUnit test or JsAssertion Framework (run on Browser), it'll throw a runtime exception (File is undefined object). Could you make sense with my means?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
Hi Khoa,

Yes, it makes complete sense, but I don't think you have many choices.

Either you would have to put wrappers around the calls to the Adobe classes so that you can use a differnent wrapper in the unit tests or the real code.
Alternatively write some mocks of the Adobe Core Javascript classes.

I think the first is probably more flexible, and you may be able to do it in pieces.

Don't think I can offer a better solution than that.
If you want to test outside of InDesign then you have to create a seam between your code and the Adobe classes.

Good luck
Caerwyn
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 19, 2008 Sep 19, 2008
LATEST
Thanks your cooperation, Caerwyn.
I understand my problem and I'll try do as your suggestion.

Thank you so much.

Khoa
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines