-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Time Watcher #552
Time Watcher #552
Conversation
micros -> toMicros, millis -> toMillis, seconds -> toSeconds fixed Javadoc 3 lines to tab startTime -> startNanos endTime -> endNanos enum SUCCEEDED - > PASSED equalTo -> is(equalTo)
I changed the following. fixed Javadoc "its" |
@Tibor17 - Good point about |
Works fine for me. |
* | ||
* <pre> | ||
* public static class TimeWatcherTest { | ||
* private static final Logger logger = Logger.getLogger(""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation looks off here and on the following lines.
* protected void finished(long nanos, Description description) { | ||
* logInfo(description.getMethodName(), "finished", nanos); | ||
* } | ||
* }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe simply overriding finished
would make a more simple example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think, only simply overriding the method is not enough. I tried to put some example of use since i think the people mostly want to log the time.
The reason why i started this pull now was that i needed some benchmark testing for ParallelComputer into our wiki. I am missing such feature in the JUnit.
So i do not want to use try-finally in our tests for such benchmark tests.
This Stopwatch would help others as well.
I think |
@marcphilipp |
The only caveat with |
@dharkness There's also a class with that name somewhere in Spring but, as you said, as it performs a similar function, I think that will do no harm. |
We should have all changes done now.
|
public static long timeSpentIfFinished; | ||
public static String testName; | ||
public static String testNameIfFinished; | ||
public static TestStatus status; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think extracting these static members into an own class, say Recording
, would make the whole test easier to read. That way, you could simply assign a new instance to a single static field in the @Before
method. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem to modify this style of code.
thx.
@marcphilipp |
IMHO this pull is almost ready to be merged. @dsaff Can you please take a look? |
Sorry to come in so late. What would you think about, rather than putting nanos in overridden methods from TestWatcher, instead exposing the time spent through a protected method? The current approach means that subclasses have the option of overriding one of two skipped, failed, etc. methods. |
@dsaff @dharkness |
Oops. I think I may have misled you. I like this idea of this being a different class. I'm just imagining a slightly different API. Where you have
I'm imagining:
That said, I'm also wondering if this belongs in the core. While rules can be used for timing and such things, they're somewhat unwieldy, since they have to be added to each class that you want timed. |
I can see a technical problem to get the value returned by If you override any of these methods, then A solution would be to make private methods package-private Now it looks like i am complicating it too much. |
Ah, you're right. I hadn't thought of that. Back to review... |
Thanks! |
@dsaff The test may use it as
Whould it be enough interresting feature? |
I could see that as an interesting follow-on commit, yes. |
If you want to measure time spent by a test, you have to do one of the following:
The Rules is an elegant solution for that.