Ubuntu 16.04与Eclipse Oxygen环境下Randoop配置方法咨询(Java8项目)
Hey there! I’ve set up Randoop for Java 8 projects on Ubuntu 16.04 with Eclipse Oxygen before, so let me walk you through the process step by step:
1. Install Randoop First
- Make sure you have Java 8 JDK installed on your Ubuntu 16.04 system. Check with
java -version—if not, runsudo apt-get install openjdk-8-jdkto install it. - Download a Randoop version that supports Java 8 (look for releases like 4.3.x, since newer versions may require higher Java versions). Grab the
randoop-all-xxx.jarfile and place it in a convenient directory, e.g.,~/tools/randoop/.
2. Configure Randoop in Eclipse Oxygen
2.1 Prepare Your Java Project
- Open Eclipse and confirm your project is set to Java 8: Right-click your project →
Properties→Java Build Path→Libraries, ensure the JRE System Library is Java 8. Then go toJava Compilerand set the Compiler compliance level to 1.8.
2.2 Set Up External Tools for Randoop
This lets you run Randoop directly from Eclipse without switching to the terminal:
- Click
Run→External Tools→External Tools Configurations. - On the left, select
Program, then click the plus icon (+) to create a new configuration. - Fill in the details:
- Name: Pick something descriptive, like
Randoop Generate Tests - Location: Browse to your Java 8
javaexecutable path. For OpenJDK, it’s usually/usr/lib/jvm/java-8-openjdk-amd64/bin/java(confirm withwhich javaif you’re using Oracle JDK). - Working Directory: Select your project’s root directory, use the variable
${workspace_loc:/YourProjectName}(replaceYourProjectNamewith your actual project name). - Arguments: Enter the Randoop command parameters. Here’s a basic example:
Breakdown of key parameters:-jar ~/tools/randoop/randoop-all-xxx.jar gentests --testclass=com.yourpackage.YourTargetClass --outputdir=src/test/java/com/yourpackage --junit-output-style=JUnit4gentests: Tells Randoop to generate tests--testclass: Specify the class(es) to test (separate multiple classes with commas)--outputdir: Directory to save generated test files (match your project’s test directory structure)--junit-output-style=JUnit4: Generates JUnit 4 tests (Eclipse Oxygen has great support for this)- Optional extras:
--timelimit=60(limit test generation to 60 seconds),--maxsize=100(max statements per test method)
- Name: Pick something descriptive, like
- Switch to the
Environmenttab, add or confirmJAVA_HOMEpoints to your Java 8 JDK path (e.g.,/usr/lib/jvm/java-8-openjdk-amd64). - Click
Applyto save the configuration.
3. Run & Validate Generated Tests
- Launch the Randoop configuration via
Run→External Tools→Randoop Generate Tests. - Navigate to the
outputdiryou specified—you’ll find generated test classes likeYourTargetClassTest.java. - Right-click the test class in Eclipse →
Run As→JUnit Testto execute the tests. - If you hit compilation errors, chances are you’re missing dependencies in Randoop’s classpath. Add the
--classpathparameter to your arguments, including your project’s compiled class directory and any dependency jars:--classpath=bin:/path/to/your/project/deps/commons-lang3.jar:/path/to/another/dep.jar
4. Quick Tips
- To generate tests for an entire package, use
--testpackage=com.yourpackageinstead of--testclass. - Randoop’s generated tests might have redundant cases—feel free to clean them up (delete unnecessary methods, adjust assertions) to fit your project’s needs.
- Stick to Randoop versions that explicitly support Java 8 to avoid compatibility issues.
内容的提问来源于stack exchange,提问作者Pooja
相关产品推荐
相关产品推荐

