Code Robo
Formatter
Comparator
Tester
Converter
Utility
Java Code Complience
Validator
EncoderDecoder
Virtual Service
Generate JUnit Test Cases
       Talk to EasyAssistant

For any Java/J2EE project we wirte lot many java classes. To do the unit test of those Java classes normally we used to write JUnit test cases. Here we have online Junit Tool to generate JUnit test cases for each java class.. Generating Junit testcases common requirement in any Java/J2EE development project.Take Java Code as input and generate JUnit test class as output.

This tool supports following important features:
  • Test suites
  • Test runners
  • JUnit classes
  • Supports both JUnitVersion 4.0 and Version 5.0
Gnerated code uses following classes:
  • Assert - Contains assert methods.
  • TestCase - defines the fixture to run multiple tests.
  • TestResult - Collect the results of executing a test case.
Java Code.(* Required): It is required.
Include Private Methods Also JUnit Version :        JUnit 4.0 JUnit 5.0


How It Works:
First format the java source code and then parse it. Extract the tokens. Generate JUnit class and add a test method for each non-private methods. Equate the actual and expeted value. If expected and actual value does not match, it fail the test cases. It generate code to handle exception and fail the test case if there is any exception.
. Input Parameters are:
  1. Java Code - Which is used to generate the JUnit test cases
  2. Generate Test Cases For Private Methods - Generate unit test cases for private method
  3. Click on the button 'Generate JUnit '
User Comments:
Shefali Chadha (2022-04-16) :
Can I generate JUnit test case for a single method only?
    Reply;
easycodeforall(admin): (2022-04-21)
You can generate a JUnit test case for a single method. But in the generated JUNit code there will be a default JAVA class name.
    Reply

Prathibha Maheshwari (2022-04-16) :
Is there a way to generate two test methods for a single java public method in a class?
    Reply;
easycodeforall(admin): (2022-04-21)
At present it will generate only one test method per method. It does not support more than one test method per method. If you can let us know more about your requirement details, we may think of adding this feature in future. Thanks for using easycodeforal !.
    Reply

anonymous (2022-04-16) :
It's not generating test method correctly for following cases. After code generation maual modification is required.

//---------------------------------------------------------//
public void senMsg(Exception ex, List authList) {
System.out.println("---------------------");
}
//---------------------------------------------------------//

    Reply;

abcd@gmail.com (2022-07-19) :
upgrade to Junit5 please
    Reply;
easycodeforall: (2022-04-21)
Thanks for using easycodeforall and puting a enhanancement request.! We will start supporting Junit5 soon.
    Reply
easycodeforall: (2022-04-21)
We have added JUnit 5 features. JUnit Code can be generate for both JUnit version 4.0 and 5.0
    Reply

abcd@gmail.com (2022-10-07) :
@Override
protected ResponseEntity handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
Map body = new LinkedHashMap();
body.put("timestamp", new Date());
body.put("status", status.value());

//Get all errors
List errors = ex.getBindingResult()
.getFieldErrors()
.stream()
.map(x -> x.getDefaultMessage())
.collect(Collectors.toList());
body.put("errors", errors);
return new ResponseEntity<> (body, headers, status);
}
how to write the junit test case for the above code?
    Reply;
easycodeforall: (2022-10-13)
There was a defect. It was not generating JUnit test cases for protected methods. Now it has been corrected. You can use the above code to generate JUnit test cases for your protected methods.
    Reply

abcd@gmail.com (2022-10-13) :
public enum Service type{ retrievenameandaddresss("retrievenameandaddress", "data","WF","dataybc","track","MZ","MZ","null), }
    Reply;
easycodeforall: (2022-11-28)
Sorry! We didn't get your question. You can send us email at easycodeforall@gmail.com. Even we can setup a google meet session if required.
    Reply
easycodeforall: (2022-11-28)
Sorry! We didn't get your question. You can send us email at easycodeforall@gmail.com. Even we can setup a google meet session if required.
    Reply

abcd@gmail.com (2022-11-28) :
Can we Junit Test cases using mockito?
    Reply;
easycodeforall: (2022-11-28)
Mockito is to build mock services. JUnit is a framework to write unit test cases for a java class and its methods. It can be run from eclipse (IDE) or command line.
    Reply

Frank (2023-04-04) :
It's not generating Junit test case for the following method correctly.
protected Query modifyStatement(@NotNull final ResResolver resolver, @NotNull final QryBuilder builder) {
    Reply;
easycodeforall: (2023-07-05)
It has been fixed. Can you please check now.
    Reply

aparna roy (2023-06-12) :
when i wrote my method here and click on generate junit i found nothing like empty why
    Reply;
easycodeforall: (2023-07-05)
It supports only single method. But a complete method needs to be added as input to this tool.
    Reply

madhu (2023-06-14) :
private methods are not working properly
    Reply;

abcd@gmail.com (2023-09-26) :
Please let me know why I am not able to generate test cases for the below class and how to ?
public class Student
{
    String name;
    // Marks in various subjects
    int english;
    int telugu;
    int hindi;
    int maths;
    int science;
    int social;

    int getLanguagesTotal()
    {
        return english + telugu + hindi;
    }

    int getNonLanguagesTotal()
    {
        return maths + science + social;
    }

    int getAllSubjectsTotal()
    {
       if (getLanguagesTotal() > 180)
       {
        return getLanguagesTotal() + getNonLanguagesTotal();
       }
      else
      {
      return getNonLanguagesTotal();
       }
    }


    Reply;
easycodeforall: (2023-09-27)
your methods are not private / public. If you use private or public methods , test cases will be generated. Though its a limitation in the current tool. We will try to address soon atleast for protected methods. Default methods are difficult to address.
    Reply

anonymous (2023-11-09) :
is this JUNIT test is generating for all methods in java in the world ?
    Reply;


Post Your Comment:
Name :
Email ( Optional) :
Comments / Suggestion (* Required) It is required: :
: