Solved

How to build a reusable testcase libray?

Posted on 2013-07-01
2
383 Views
Last Modified: 2013-12-13
Hi,

I hope I am asking this correctly.

I was wondering if I can get a guidance or example on how to go about building a JUnit reusable testcase library.

If I am testing a method that checks for a string, I would like to create one testcase and use that over and over again on my other project.

If I am comparing integers on a method, I wouldl ike to write up one testcase and use that in other projects.

I don't know if this is done regularly by other programmers.
Any advise will be greatly appreicated.
0
Comment
Question by:dkim18
2 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
Comment Utility
You can write a superclass with all the necessary test methods you need, and then extend this class with every test case. By doing so you can reuse the commonly used test cases and you can define specific functionality in each subclass.
0
 
LVL 28

Assisted Solution

by:pepr
pepr earned 250 total points
Comment Utility
Independently on a language and a unit test framework... When you want to reuse the method in other projects, how would you do that? If you find a bug in the method (in future), how would you fix the bug in all the projects?

The simple but labour-intensive way is to copy the code of the method to the other projects from one of the projects that you consider a referential one. It can be a project that is used just for the development and for testing of that method. When you find the bug in the methode elsewhere, you write the new test for the reference project and fix the code there. Then you copy the code of the method to the other projects.

The alternative way is to create the library/package for implementing the functionality. After fixing the bug you only rebuild the project that depend on the functionality. This is probably what should be prefered. However, it may be the case that the first approach is more economic at first. It depends on more things.

Definitely, you should start somehow (with unit testing...). Then you gradually gain the experience, and you will know what next.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If your app took Google’s lash recently, here are the 5 most likely reasons.
In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now