Post

2 followers Follow
0
Avatar

Unit / Integration tests using TestGeneious

I am refactoring and porting our Geneious plugin for Geneious Prime.

 

I have an enum class that is pretty central to all code within the plugin. But while the enum constants initialize (i.e. in the private constructor) Geneious APIs like

  • DocumentNoteUtilities.getNoteType
  • DocumentNoteUtilities.createNewNoteType

are called. These of course implicitly execute database DML.

Therefore I can't see how to create unit tests for other classes that directly or indirectly depend on this enum class (pretty much all).

 

I have tried TestGeneious.initialize() and TestGeneious.initializeAllPlugins() in my JUnit @BeforeClass method. But that didn't work.

How should I go about this?

 

Ayco

 

Informatiemanagement

Official comment

Avatar

Hi Ayco,

You are on the right track.

The next steps depend on exactly what you are trying to do. For a test I just created TestGeneious.initializeAllPlugins() was enough to use createNewNoteType and getNoteType.

Note that you need to call DocumentNoteUtilities.setNoteType before using getNoteType to retrieve a newly created note type.

If that still isn't working because the local database is not set up then add the following to your test:

TestGeneious.initializeAllPlugins();
PluginUtilities.getGeneiousService("LocalDocuments");

I hope that helps.

Cheers,
Jason

Jason
Comment actions Permalink

Please sign in to leave a comment.

3 comments

0
Avatar

Hi Jason,

I finally figured it out - though in retrospect it's all pretty obvious. My (Eclipse) should of course be exactly like if I were to run Geneious with one of the example plugins or my own plugin ... e.g. workdir settings and LD_LIBRARY_PATH settings (latter not necessary but prevents warnings).

 

It would be good to warn developers about this in the TestGeneious class. Or maybe also include an example unit test in one of the example plugins.

 

Bye,

 

Ayco

Informatiemanagement 0 votes
Comment actions Permalink
0
Avatar

Hi Ayco,

I'm glad that you found the solution. Thanks for posting it here for others to find.

Your suggestion is a good one. I have raised a ticket to improve the documentation. This of course will have to be prioritized relative to other work so I cannot guarantee if or when it will get done.

Cheers,
Jason

Jason 0 votes
Comment actions Permalink