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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:23:00+00:00 2026-05-25T12:23:00+00:00

I am running groovy by embedding it in a Java application via the following

  • 0

I am running groovy by embedding it in a Java application via the following code:

GroovyScriptEngine gse = null;
  try {
  //note that roots is properly defined above i just didn't include it in this example so that it
  //remains concise 
     gse = new GroovyScriptEngine(roots);
  } catch (IOException ex) {
     Logger.getLogger(GroovyWrapper.class.getName()).log(Level.SEVERE, null, ex);
  }

Now I have another groovy script with the code below (which i execute on a button click). Again the code is simplified but it works correctly and the started script can see and use the file I am trying to JUnit test without issues:

GroovyScriptEngine gse = new GroovyScriptEngine(roots);
gse.run(relativeScriptName, binding);

The script I am executing has the following code:

class AllTests extends TestSuite {
   static TestSuite suite() {
      TestSuite suite = new TestSuite();
      GroovyTestSuite gsuite = new GroovyTestSuite();

         suite.addTestSuite(gsuite.compile("LibraryTest.groovy"));

      return suite;
   }
}

TestRunner.run(AllTests.suite())

Now what I am noticing is that even the above script (AllTests) can import and use the file I want to JUnit test, but the the JUnit test itself fails with an “unable to resolve class” exception when the TestRunner above runs the JUnit test. And it fails when i just import the class. The JUnit test i’m running is summarized below:

package lib

import groovy.util.GroovyTestCase
import lib.Dictionary;

class LibraryTest extends GroovyTestCase {


   public void testSomething() {
      assert 1 == 1
      assert 2 + 2 == 4 : "We're in trouble, arithmetic is broken"
   }

}

Note that the JUnit test passes and runs correctly if i don’t import the class i want to test. But the JUnit test isn’t much use to me unless I can use it to test my other groovy classes and scripts.

Any thoughts?

  • 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-25T12:23:00+00:00Added an answer on May 25, 2026 at 12:23 pm

    Ok I figured out the issue. For some reason I need to compile all the groovy scripts that my tests will use even though I don’t have to compile any of them if I just call them using groovy (ie. standard groovy usage). I hope this saves other people some time in debugging. To compile a file just use

    gsuite.compile("<file name>");
    

    in my code above.

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

Sidebar

Related Questions

I have a Java application that is running embedded groovy scripts using a GroovyClassLoader
Running my script through Devel::NYTProf showed that the following portion of code took up
I'm new to Java and Groovy and am running into trouble with the following
I have a problem with running java code from groovy script (groovy script is
I'm running a project that has a dependency on groovy 1.7-beta-1. The gmaven plugin
The following Groovy code creates a GORM-persisted domain class called Foo when written to
I am running a web application in Production that recently crashed after it was
I have a groovy application running locally on my desktop. Apparently it runs error
while running following code : def v1=[]; def p=[]; v.as('x') .except(v1).sideEffect{v1.add(it)} // step 1
We are developing a webapp that needs to send out emails written in Java/Groovy.

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.