Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8401259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:45:34+00:00 2026-06-09T21:45:34+00:00

I am trying to make some JUnit tests for my code. But the problem

  • 0

I am trying to make some JUnit tests for my code. But the problem is, I make use of the Java Models like ICompilationUnit, IPackageFragment, ITypes and etc. I did not get how to create some ICompilationUnit and then test. I searched google and stackoverflow for information but did not find something.

My question is, how can I make Junit test with classes of the jdt.core…can somebody give me may be some code examples.

Thanks

Here is a Method I coded:

private void updateLists() {

    if(!getCompilationUnit().isEmpty()){

        for(int i = 0;  i < getCompilationUnit().size(); i++){

        try {

                Document doc = new Document(getCompilationUnit().get(i).getSource());

                int totalNumberOfCode = doc.getNumberOfLines();

                IType type = getCompilationUnit().get(i).findPrimaryType();                 

                                    IType[] types = getCompilationUnit().get(i).getTypes();

                updateListPrimaryType(type, totalNumberOfCode, types);

                updateListIMethod(type);
                updateListMember(type,types);


            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:45:36+00:00Added an answer on June 9, 2026 at 9:45 pm

    This snippet of code shows how to take some Java source (in variable javaSource) and get an ICompilationUnit from it by using the Java AST parser. You get these classes by using plugin org.eclipse.jdt.core as a dependency.

    import org.eclipse.jdt.core.dom.ASTParser;
    
    String javaSource = "some java source"'
    
        // see org.eclipse.jdt.core.dom.AST for a complete
        // list of supported levels.
    ASTParser parser = ASTParser.newParser(AST.JLS2);
    parser.setSource(javaSource.toCharArray());
    CompilationUnit unit = (CompilationUnit) parser.createAST(null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make some simple XML with Java and org.w3c.dom, but I got
I'm trying to make some input fields that I would like to work like
I'm trying to make some common scopes for models to be sharing, so i
I'm trying to make some text bold using HTML, but I'm struggling to get
I'm trying to make some social share buttons at my site, but the urls
I'm trying to make some communication for my PIC devices and I use UDP
i am trying to make some sense of an error code being returned when
Currently I'm trying to make some sort of vertical auto-scrolling. This is my code
I'm trying to make some code which finds if a div exists, and if
I am trying to make some sort of timeline, but I can not keep

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.