[tor-bugs] #12881 [Onionoo]: Mocking framework for testing
Tor Bug Tracker & Wiki
blackhole at torproject.org
Mon Aug 18 21:01:38 UTC 2014
#12881: Mocking framework for testing
-----------------------------+-----------------
Reporter: iwakeh | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone:
Component: Onionoo | Version:
Resolution: | Keywords:
Actual Points: | Parent ID:
Points: |
-----------------------------+-----------------
Comment (by iwakeh):
When introducing a third party dependency anyway, jmockit 1.10 would be
the way to go.
Example for setting the time (e.g. in UptimeDocumentWriterTest with its
TEST_TIME) inside a test method:
{{{
@Test
public void testMockTime() {
long justNow = System.currentTimeMillis();
new MockUp<System>() {
@Mock
public long currentTimeMillis() {
return TEST_TIME;
}
};
assertTrue( (new Date(System.currentTimeMillis())).before(new
Date(justNow)));
}
}}}
That would save several test classes and the application code for the
util.Time class.
--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/12881#comment:2>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online
More information about the tor-bugs
mailing list