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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:56:38+00:00 2026-06-04T09:56:38+00:00

I want to run a single unit test and collect its profiling information: how

  • 0

I want to run a single unit test and collect its “profiling” information: how often every method was called, how many instances of certain class were created, how much time did it take to execute certain method/thread, etc. Then, I want to compare this information with some expected values. Are there any Profilers for Java than let me do this (all this should be done automatically, without any GUI or user interaction, of course)?

This is how I want it to work:

public class MyTest {
  @Test
  public void justTwoCallsToFoo() {
    Profiler.start(Foo.class);
    Foo foo = new Foo();
    foo.someMethodToProfile(); // profiler should collect data here
    assertThat(
      Profiler.getTotalCallsMadeTo(Foo.class, "barMethod"), 
      equalTo(3)
    );
  }
}
  • 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-04T09:56:39+00:00Added an answer on June 4, 2026 at 9:56 am

    I found out that this could be done with a J2SE built-in HPROF profiling tool.

    java -agentlib:hprof=cpu=times MyTest
    

    It produces a text file formatted like this:

    CPU SAMPLES BEGIN (total = 126) Fri Oct 22 12:12:14 2004
    rank   self  accum   count trace method
       1 53.17% 53.17%      67 300027 java.util.zip.ZipFile.getEntry
       2 17.46% 70.63%      22 300135 java.util.zip.ZipFile.getNextEntry
       3  5.56% 76.19%       7 300111 java.lang.ClassLoader.defineClass2
       4  3.97% 80.16%       5 300140 java.io.UnixFileSystem.list
       5  2.38% 82.54%       3 300149 java.lang.Shutdown.halt0
    ....
    

    Then it’s easy to parse the file and extract the methods you’re interested in. The solution is completely free and JSE built-in, which is a great benefit comparing to other tools.

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

Sidebar

Related Questions

I want to run multiple instances of apache on one single machine? How to
Can you run a test for a single method only, not a whole class?
I want to run single test class from command line using Maven and TestNG
I want to run parallel codes on single pc with core i7 cpu I
I want to run the following jquery code on every page in my website.
I have like trillion test packages with bazillion tests and I want to run
I have two distinct Django projects, which I want to run on a single
I want to run code coverage in my unit tests. The issue is that
I want to run a single MYSQL command on the CLI, i made a
I'm trying to unit test my websocket on node.js and want to mock out

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.