elstar IT

Fullstack | Java | Tech Speaker | Tech Coach | Frank van der Linden

  • About me
  • Blog license
  • My Open source projects

Basic testing of the JUnit for XPages plugin

25-08-2014 no responses flinden68 development

Last week Christian Guedemann has released on OpenNTF a new project, JUnit testing for XPages, I think a missing part of the Domino Designer experience, especially with the increasing use of Java in XPages apps.

So this weekend I did some basic Unit testing.

Test Driven Development

The last 10 month I did most of the time ‘real’ Java development. At a customer I stepped in the Enterprise Java Development, and all the tooling around this type of Development. One of these things was Test Driven Development (TDD), write unit tests before actually writing code.

TDD follows roughly a cycle as shown below.

[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]UNIT_TEST_TDD[/dropshadowbox]

It require also a other way of development. Like single responsibility of methods. For Unit testing in Java there are also great tooling, Mock Frameworks, like Mockito, EasyMock and PowerMock. These frameworks simulate objects and can be used to match the expected result.

 

A small warning

On for hand I should warn you, I am not that good in writing Unit tests. I have a lot to learn 😉 And writing tests after writing code is not the way.

 

OK, the testing.

After all the downloading and installing of the plugin and put the demo database on my Domino server. I was ready to go.

The demo database provides a very good way who to use the plugin, see the blog of Christian.

So I created a Test class, to test if a Document could be found by providing a document UNID.

[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]Screen Shot 2014-08-25 at 21.35.03[/dropshadowbox]

So far so good.

Another small test was giving me a challenge. The method I wanted to test was accepting a Document object. So I added a Mock Framework.

First I tried Mockito, but I ran into problems by initializing the the Mockito Annotations, returning me a nasty stack trace.

So I switched to EasyMock. Added it to my lib directory of my database and added it to the build path.

Now I was able to simulate a Document and set the class to be tested as the TestSubject.

[dropshadowbox align=”none” effect=”lifted-both” width=”600px” height=”” background_color=”#ffffff” border_width=”1″ border_color=”#dddddd” ]Screen Shot 2014-08-25 at 21.42.22[/dropshadowbox]

As you can see, nothing special, mostly because the code was already written, and I was not willing to change it.

 

Conclusion.

The plugin is working very easily. Adding new classes to your JUnit plugin was very easy. One of the things I was missing, and I already discussed it with Christian, was a Mock Framework. When it will be added to the plugin it will add more value to the plugin. Because you don’t need to add a Mock Framework by yourself to the database.

Like Ryan Baxter also mentioned in the discussing, add also PowerMock, which will nicely work together with EasyMock. PowerMock let you test also static methods and objects.

 

Tags: java, unittesting, xpages

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • « Domino 9.0.1 FP2 break DOTS
  • The moment is here to become a freelance developer »

Contact me

My name is Frank van der Linden and I am an independent software developer based in the Netherlands. The last 2 years I was awarded as IBM Champion. Also I am on the board of OpenNTF. My specialisations are Java, Web development and Domino.


If you want to hire me, please fill in the Contact form


IBM Champion web badge
Apache Logo

All the code on this blog are under the Apache License 2.0. For more details, see Apache License 2.0

Most recent posts

  • Engage 2020: Hello are you listening, There is stream for everything
  • Spring Cloud Function on Azure run locally
  • Deploy Spring Cloud Function to IBM Cloud
  • Speaking (again) at Engage in a Zoo
  • Congratulations, you’re an IBM Champion (again)!

Latest reactions

  • Spring Cloud Function on Azure run locally - elstar IT on Deploy Spring Cloud Function to IBM Cloud
  • flinden68 on Quick XPages tip: add Fullcalendar plugin to your application
  • Rajesh samal on Quick tip: Swagger support for Spring Webflux
  • dsieyx on Quick XPages tip: add Fullcalendar plugin to your application
  • John on Named as IBM Champion 2019

Archive

  • March 2020
  • February 2020
  • January 2020
  • October 2019
  • September 2019
  • June 2019
  • May 2019
  • April 2019
  • March 2019
  • January 2019
  • December 2018
  • October 2018
  • September 2018
  • May 2018
  • April 2018
  • March 2018
  • February 2018
  • January 2018
  • December 2017
  • November 2017
  • October 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • December 2016
  • November 2016
  • October 2016
  • September 2016
  • August 2016
  • June 2016
  • May 2016
  • April 2016
  • March 2016
  • February 2016
  • December 2015
  • November 2015
  • October 2015
  • September 2015
  • August 2015
  • July 2015
  • June 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • May 2014
  • April 2014
  • March 2014
  • February 2014

Category

  • bluemix
  • business
  • cloudant
  • community
  • development
  • hrassistant
  • openntf
  • running
  • salesforce
  • Springboot
  • Tesla
  • trailrunning
  • Uncategorized
  • watson
  • OpenNTF
  • Collaboration Today
  • XSnippets
  • Stackoverflow
  • IBM Collaboration Solutions
  • Social Business Toolkit
  • About me
  • Dutch curriculum vitae
  • English curriculum vitae
  • Google+
  • LinkedIn profile
  • Twitter
  • Slideshare
  • Blog license
  • My open source projects