[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-bugs] #12881 [Onionoo]: Mocking framework for testing



#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
_______________________________________________
tor-bugs mailing list
tor-bugs@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-bugs