Unit Testing Business Rules
Hi Frevvo!
I was wondering what options do I have to set up unit tests with the business rules. Currently our business rules get very big with many different responsibilities. This isn't ideal but it is what we have to work with. I was wondering how could I set up unit tests to test the different features of a single business rule? I was thinking of using the business rules server in some way to run tests.
This is an example of what I am looking for
Business Rule Name : Form Load
Description: Sets values, drop downs and accessibility to form
if (form.load)
{
//Current User viewing form
var Cuser = _data.getParameter('subject.id');
//Create Doc Type List
var w = null;
eval ('w=' + http.get('http://localhost:8082/database/TEST/getDocType'));
var opts1= [];
for (var i=0; i < w.resultSet.length; i++)
{
if (w.resultSet[i])
{
opts1[i] = w.resultSet[i].ListItem + '=' + w.resultSet[i].ListItem ;
}
}
ddlOptions.options = opts1
if (!ddlOptions.value)
{
radCheck.enabled = true;
}
else
{
radCheck.value = 'Yellow';
}
}
In the above example I would want to make sure the http requests are going out correctly if there isn't a value in ddlOptions the if statement is enabling radCheck, etc.
Right now my team and I are in a fear driven deadlock. We don't want to make any changes to optimize our business rules yet we still have to make work around changes. The more of these we do the worse the code gets.
-
Hi Daniel,
I don't think it would be possible to setup unit tests to test different features of a single business rule. However, you could use try-catch statements (see this documentation) with custom logging (see this documentation) in your business rules for better debugging.
I am not sure I understand what you mean by source of the Business Rules. If you are looking for a way to get the code for all the rules in a form in one place, then you can use the View All feature for that.
1 -
Also how can I get to the source of the Business Rules? That would help me refactor the code for the changes that are constantly being requested and implemented.
0 -
Hi Prajakta,
Sorry for the really late reply and thank you for your response! I am looking for a few things which make my ask a bit complicated. What I am looking for is the following:
- A way to put the business rules in a source control. I am currently using the view all feature you've pointed out to get a copy of the business rules. I was wondering if there was a way to get the business rules from somewhere on the server we are hosting Frevvo. I can setup a script to grab the code and push it into a version control repository.
- A way to setup selenium tests to automatically perform actions on the form as a functionality tests. What I am looking for here is the web address to access a frevvo form.
- Is there a way to run the business rules logic without having to interact with a form,that will help with unit tests?
Hope that gives some clarity. I appreciate the time you have spent already answering my questions!
0 -
Good Morning! Follow up. Thank you!
0 -
Hi Daniel,
1. The business rules are stored in the frevvo database in individual .formtype file for each form. I can't think of any easy way to get all the business rules directly from the frevvo database.
2. frevvo forms are accessible with their share URLs. Please see this documentation which explains how to get a forms share URL which you can then use in your Selenium tests.
3. You can use frevvo Data API to create form instances. I believe the rules will run in the background for such forms. Is this what you are looking for? You might want to go through these .Net API FAQs to get an idea of the functionality available via frevvo Data API.
I hope that helps.
-Prajakta
0 -
Prajakta that does make sense. It gives me enough so I can start looking into this deeper!
0
Please sign in to leave a comment.
Comments
6 comments