Jump to content
JoeDG

Testings VIs inside LabVIEW Project Libraries

Recommended Posts

I'd like to write tests for some VIs that are inside a LabVIEW Project Library. The VIs are privately scoped, so in order to test these, I need to place the test case inside the Library.

 

From what I can tell, VI tester does not "see" the test if the test case is located inside a Library. If I move it out of the library into My Computer, and save all, the tests show up in VI Tester, but of course they are broken because they contain privately scoped VIs.

 

How should I go about testing privately scoped VIs in Libraries?

 

-Joe

Share this post


Link to post
Share on other sites

 

How should I go about testing privately scoped VIs in Libraries?

 

 

You can't test privately scoped VIs directly as they can never be called outside of their library. You basically have two choices:

 

1: Test a caller of the VI (the caller can be Public or Community scoped). The caller can be created just as a wrapper for the purpose of testing the code.

 

2: Change the VI under test's scope from Private to Community and add the TestCase where you want to create tests as a 'Friend' of the library.

 

Hope that helps!

 

Omar

  • Upvote 1

Share this post


Link to post
Share on other sites

One thing I'd add (for consideration) is a link to, and quote from, a related Q&A posted on Stack Overflow:

 

Question: How do you unit test private methods?

 

Answer worth considering:

 

If you want to unit test a private method, something may be wrong. Unit tests are (generally speaking) meant to test the interface of a class, meaning its public (and protected) methods. You can of course "hack" a solution to this (even if just by making the methods public), but you may also want to consider:

 

1) If the method you'd like to test is really worth testing, it may be worth to move it into its own class.

 

2) Add more tests to the public methods that call the private method, testing the private method's functionality. (As the commentators indicated, you should only do this if these private methods's functionality is really a part in with the public interface. If they actually perform functions that are hidden from the user (i.e. the unit test), this is probably bad).

Share this post


Link to post
Share on other sites

Thanks, Omar and Jim. Jim, I think you're probably right:

 

Something may be wrong

 

:)

 

I think the problem is twofold: 1) I need to be just testing the public interface to the library and 2) The public methods are overly complex, such that their private components really *need* to be tested individually. I probably need to focus my efforts on refining my object model and then my testing strategy.

 

I'm still pretty wet behind the ears regarding TDD, and software testing in general... I'm still trying to orient myself and get a basic understanding. Maybe with a few more course corrections, I'll begin to feel like I'm accomplishing something and not just wasting time. :)

 

Thanks guys, for providing this awesome tool!

 

-Joe

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.