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

  • Home
  • SEARCH
  • 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 320353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:44:45+00:00 2026-05-12T08:44:45+00:00

My unit tests are in a separate directory tree from my integration tests, but

  • 0

My unit tests are in a separate directory tree from my integration tests, but with the same package structure. My integration tests need external resources (e.g. a server) to be available, but my unit tests are properly independent of each other and the environment.

In IntelliJ-IDEA (v7) I have defined a JUnit Run/Debug Configuration to run all the tests in the top-level package, and this of course picks up my integration tests which fail.

I want to define a run-junit configuration that runs all my unit tests. Any ideas?

  • 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-12T08:44:45+00:00Added an answer on May 12, 2026 at 8:44 am

    The answer is to create a test suite that contains only those tests underneath the unit test folder and run that instead. There is a junit-addon which does just this called DirectorySuiteBuilder but I only found this after I had pretty much re-invented the wheel.

    And it’s already been asked here!

    import junit.framework.JUnit4TestAdapter;
    import junit.framework.TestSuite;
    
    import java.io.File;
    import java.io.IOException;
    
    public class DirectoryTestSuite {
        static final String rootPath = "proj\\src\\test\\java\\";
        static final ClassLoader classLoader = DirectoryTestSuite.class.getClassLoader();
    
        public static TestSuite suite() throws IOException, ClassNotFoundException {
        final TestSuite testSuite = new TestSuite();
        findTests(testSuite, new File(rootPath));
        return testSuite;
        }
    
        private static void findTests(final TestSuite testSuite, final File folder) throws IOException, ClassNotFoundException {
        for (final String fileName : folder.list()) {
            final File file = new File( folder.getPath() + "/" +fileName);
            if (file.isDirectory()) {
            findTests(testSuite, file);
            } else if (isTest(file)) {
            addTest(testSuite, file);
            }
        }
        }
    
        private static boolean isTest(final File f) {
        return f.isFile() && f.getName().endsWith("Test.java");
        }
    
        private static void addTest(final TestSuite testSuite, final File f) throws ClassNotFoundException {
        final String className = makeClassName(f);
        final Class testClass = makeClass(className);
        testSuite.addTest(new JUnit4TestAdapter(testClass));
        }
    
        private static Class makeClass(final String className) throws ClassNotFoundException {
        return (classLoader.loadClass(className));
        }
    
        private static String makeClassName(final File f) {
        return f.getPath().replace(rootPath, "").replace("\\", ".").replace(".java", "");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 238k
  • Answers 238k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The problem is you are storing your executable in /bin,… May 13, 2026 at 6:47 am
  • Editorial Team
    Editorial Team added an answer Prince XML is a really cool tool which allows you… May 13, 2026 at 6:47 am
  • Editorial Team
    Editorial Team added an answer -cellForRowAtIndexPath: will only get called when the table view needs… May 13, 2026 at 6:47 am

Related Questions

I am learning how to use NUnit. I have my main project in it's
I am currently developing a library and a set of programs using this library,
I recently refactored some code in an Active Directory role provider to remove support
I write code primarily for personal use, but I'm considering releasing an application (scientific

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.