Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto generation of JUnit test cases as per EasyTest Framework #41

Open
ravi-polampelli opened this issue Sep 21, 2012 · 10 comments
Open

Comments

@ravi-polampelli
Copy link

As discussed during the requirements, we planned to auto generate JUnit test cases and test data.
Share any ideas here.

@ravi-polampelli
Copy link
Author

Idea No: 1:

I have below idea but it looks bit crude at the moment, we need to come-up with better sophisticated design for this.

  1. Define EasyTest case template -- with imports, class level annotation, BeforeClass, AfterClass methods etc..
  2. Define Test Data map.
  3. Static scanning of java file
  4. Check for start of the method (public), capture method signature (parameters, return types)
  5. Go through each line inside method, and see
    1. if it uses any class level variables. if so, add them in either BeforeClass method or create constructor inside test method.
    2. if it contains IF line - add boundary conditions in test data for that parameter.
    3. if it contains WHILE,FOR,DO loops - add boundary conditions for iterator
    4. if it invokes other service classes - add EasyMock objects for them in BeforeClass and see if you can add TestData for that or hard code ArrayList of return values of that service.
    5. etc..
  6. Write EasyTest JUnit test case
  7. Write Test data in EasyTest format eith XLS/XML/CSV as per user choice.

@ravi-polampelli
Copy link
Author

Idea No 2:

Look for any better open source JUnit test case generations software, and customize it to our needs

@ravi-polampelli
Copy link
Author

Idea No 3:
Code Generation tools like Velocity Templates can be thought of to decide the template structure and customize it.
AndroMDA is another such tool.

@anujgandharv
Copy link
Member

A lot of good ideas. :)
Here is what I think.
In todays world the emphasis is on Test Driven Development. Thus a project or a team defines its functionality and then the test resource of that project writes test scripts/test cases for that functionality. The developers also write Tests that initially all fail as the functionality is not there and as the functionality is developed the tests starts to pass.
In essence, a developer/tester knows what functionality is required before they start developing the functionality and they capture it by writing empty tests.

Now here is what I think and feel. If we could provide the users of EasyTest a way to generate the empty test cases which does not involve them writing Java test files, it could be a good start. Also if we could combine the efforts of a tester as well as a developer in this situation, then a given project will benefit a lot. For example, A test resource can write the test situations he feels should be tested in his own format(in our case it could be a CSV,XML,Excel file) and EasyTest framework should be able to generate Java test classes for those situations.

There are many tools available in the market. As you mentioned Velocity/AndroMDA. One I had on my mind was http://dishevelled.sourceforge.net/ it is a very light weight easy to use library. Also Java 6 has Filer options which can be used to generate Java classes.

@ravi-polampelli
Copy link
Author

That is really good idea for greenfield projects.
I liked the idea of collaborative efforts from tester and developer from beginning, which will yield good quality output and saves lot of time at later stage of discussions missing/incorrect/misunderstood requirements. What ever understanding of tester/analyst can be captured in test cases that would be great. but I am not clear on how do you generate these test cases, I mean what is the format of requirements that you can pass as input to test case generation program etc.. is there any standard mechanisms like UML use case diagrams etc?

Another important point that I want to bring forward is, maintenance projects. In my view there are 80% of maintenance projects running now as compared to green field projects. so our EasyTest should be handle that. The issue I created here is from maintenance project perspective, when they are doing big bang migration, and they have very poor JUnit test coverage(which is true in majority cases). We clearly know input is existing source code and if we provide capability of auto generating the EasyTest test cases and test data, then it would become unique selling point for EasyTest. Please think about it and let me know your views.

@anujgandharv
Copy link
Member

IMO, generating JUnit test cases for existing classes is a very nice option, but is a totally different project altogether.
May be we can create a separate project for it in github and start developing it side by side of EasyTest. What this will give us is the ability to keep EasyTest and Code generation logic spearate and yet develop it as per Easytest's basic requirements.

As goes for generating test cases for TDD, I am also not sure. May be XML/UML or any other thing. I havent thought about it in detail but this is something that will be part of the next release of EasyTest. Currently, the main focal point for easytest is to perform Data Driven testing using JUnit as well as using Spring. This is what we need to complete by 15th October and release it as version 0.5.0 in Maven.

I am already working on introducing a new Runner for Spring based Testing and it should be available soon. So the other things left is the CSV writer and seeding the DB with the test data. Lets first finish up these things and then lets focus on others.

@ravi-polampelli
Copy link
Author

Sounds good. we can create the generation as a separate project.

@anujgandharv
Copy link
Member

What happened to this Ravi? I thought you said that you have the code ready? Did I miss interpret?

@ravi-polampelli
Copy link
Author

It still progressing, I am checking some of friends here, they gave
different real life scenarios..
I am trying incorporate them also.

Did you create GitHub project for it. if so, please send those details.

On Thu, Oct 18, 2012 at 3:52 PM, Anuj Kumar [email protected]:

What happened to this Ravi? I thought you said that you have the code
ready? Did I miss interpret?


Reply to this email directly or view it on GitHubhttps://github.com//issues/41#issuecomment-9567227.

@anujgandharv
Copy link
Member

Yes, it already exists. Here is the project: https://github.com/EaseTech/easytest-codegen
Do let me know in case you need anything else. It can easily be checked out from github just like any other branch or project. I look forward to having something to test based on this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants