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 1060979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:24:32+00:00 2026-05-16T18:24:32+00:00

I made a little app to generate Java test classes based on certain set

  • 0

I made a little app to generate Java test classes based on certain set of information. Basically, I am generating the boilerplate code needed for a library that we are using.

I would like to test the generated code in better way than just comparing the output to an expected string.

  • Is there any facility to test if the Java code contains errors?
  • Is there any facility to determine if the Java file will compile?
  • Is there a strategy that I should use for this kind of situation (I was thinking of using Class class to get information about the class)?
  • 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-05-16T18:24:33+00:00Added an answer on May 16, 2026 at 6:24 pm
    • Is there any facility to test if the Java code contains errors?

    • Is there any facility to determine if the Java file will compile?

    • Is there a strategy that I should use for this kind of situation?

    Yes – compile the file with the Java compiler.

    Note that you can call the Java compiler at runtime, either by using Runtime.exec(...) or the the JavaCompiler API. The latter approach is described in:

    • How do I programmatically compile and instantiate a Java class?

    and there are lots of other resources on the subject.

    However, your primary goal seems to be to check that your generators are generating correct Java code; e.g. as part of your application tests. For that, it would be simplest to off-load the problem to a shell script that uses javac to the compile the code with an appropriate classpath, checks the compiler’s return code, and greps the compiler output for error and warning messages.

    But … as you are probably aware … simply compiling the generated code doesn’t guarantee that it will be correct.


    I was thinking of using Class class to get information about the class.

    That won’t help. The Class class is only relevant for classes that have been successfully compiled and successfully loaded by the JVM. And even then it doesn’t tell you if there were syntax (or other) errors in the original code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is some of the main code for a little app I have made
i want to test handling phone calls, so i made a little app, it
I made a GPS based app, which works perfectly except for a little mistake.
I made this little function from code snippets around the net. It does what
I have made a YUI module a little like the code shown below, which
I wrote a little Java servlet that would dynamically generate an image button given
I made a little app that does nothing to see if I could put
I'm a beginner with C# so I made a little app, to figure out
I made a little cocoa app that brings up an IKPictureTaker and saves a
I've got something happening with a little app that I made that I don't

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.