generating readable unit
play

Generating Readable Unit Tests for Guava Ermira Daka, Jos Campos, - PowerPoint PPT Presentation

Generating Readable Unit Tests for Guava Ermira Daka, Jos Campos, and Gordon Fraser University of Sheffield Jonathan Dorn and Westley Weimer University of Virginia ESEC/FSE 2015 [Developers] read tests [] 77% of the total time they


  1. Generating Readable Unit Tests for Guava Ermira Daka, José Campos, and Gordon Fraser University of Sheffield Jonathan Dorn and Westley Weimer University of Virginia ESEC/FSE 2015

  2. “[Developers] read tests […] 77% of the total time they spend in them” Moritz Beller, Georgios Gousios, Annibale Panichella, and Andy Zaidman. When, How, and Why Developers (Do Not) Test in Their IDEs. FSE 2015

  3. public final class MoreExecutors { private MoreExecutors() {} … public static Executor directExecutor() { return DirectExecutor. INSTANCE; } … public static ListeningExecutorService listeningDecorator( ExecutorService delegate) { return (delegate instanceof ListeningExecutorService) ? (ListeningExecutorService) delegate : (delegate instanceof ScheduledExecutorService) ? new ScheduledListeningDecorator((ScheduledExecutorService) delegate) : new ListeningDecorator(delegate); } … }

  4. public class MoreExecutors_ESTest extends MoreExecutors_ESTest_scaffolding { @Test public void test0() throws Throwable { Executor executor0 = MoreExecutors.directExecutor(); MockThread mockThread0 = new MockThread(); int int0 = 0; ScheduledThreadPoolExecutor scheduledThreadPoolExecutor0 = new ScheduledThreadPoolExecutor(int0); ListeningScheduledExecutorService listeningScheduledExecutorService0 = MoreExecutors.listeningDecorator((ScheduledExecutorService) scheduledThreadPoolExecutor0); long long0 = 1L; TimeUnit timeUnit0 = TimeUnit.MILLISECONDS; int int1 = (-774); LinkedBlockingDeque<Runnable> linkedBlockingDeque0 = new LinkedBlockingDeque<Runnable>(); ThreadPoolExecutor.DiscardOldestPolicy threadPoolExecutor_DiscardOldestPolicy0 = new ThreadPoolExecutor.DiscardOldestPolicy(); int int2 = 0; int int3 = 431; TimeUnit timeUnit1 = TimeUnit.MINUTES; ThreadPoolExecutor threadPoolExecutor0 = new ThreadPoolExecutor(int0, int3, long0, timeUnit1, (BlockingQueue<Runnable>) linkedBlockingDeque0, (RejectedExecutionHandler) threadPoolExecutor_DiscardOldestPolicy0); BlockingQueue<Runnable> blockingQueue0 = threadPoolExecutor0.getQueue(); ThreadFactory threadFactory0 = scheduledThreadPoolExecutor0.getThreadFactory(); TimeUnit timeUnit2 = TimeUnit.MINUTES; int int4 = (-188); TimeUnit timeUnit3 = TimeUnit.HOURS; ThreadPoolExecutor threadPoolExecutor1 = null; try { threadPoolExecutor1 = new ThreadPoolExecutor(int0, int4, (long) int0, timeUnit3, (BlockingQueue<Runnable>) linkedBlockingDeque0, threadFactory0); } catch(IllegalArgumentException e) { // // no message in exception (getMessage() returned null) // } } }

  5. ESEC FSE 2015

  6. Test readability judgments 7

  7. Test readability judgments • 15,669 human judgments of readability

  8. public void test0() throws Throwable { String string0 = ""; String string1 = "]"; MessageDigestHashFunction messageDigestHashFunction0 = null; try { messageDigestHashFunction0 = new MessageDigestHashFunction(string0, string1); } catch(AssertionError e) { // // java.security.NoSuchAlgorithmException: MessageDigest not available // } } Test Length = 10 Unique Identifiers = 3 Max Line Length = 77 … 99 other features Has Exception = True Constructors = 1 Assertions = 0 String Length = 1 9

  9. Feature predictive power max line length total identifier length avg identifier length total constructor calls total line length max identifier length total unique identifers total identifiers total distict methods token entropy total floats max nulls avg string length total numbers avg loops avg nulls identifier ration has exceptions total assertions avg branches max characters avg arithmetic operators method ratio has assertions 10 0 0.1 0.2 0.3 0.4 0.5 0.6

  10. • Readability as secondary objective • Individuals with same coverage based fitness are ranked by readability score • Readability part of multi-objective algorithm • NSGA-II including readability score as fitness Readable test case

  11. Class selection for test readability evaluation GUAVA base.Splitter math.DoubleMath Optimize Test net.PercentEscaper Cases for primitives.UnsignedBytes Readability Util.concurrent.MoreExecutors

  12. Readability improvement 80 70 60 50 40 30 20 10 0 base.Splitter math.DoubleMath net.PercentageEscaper primitives.UnsignedBytes util.conurrent.MoreExecutors Readability as SO Readbility as MO

  13. Readability improvement 4 3 2 1 0 base.Splitter math.DoubleMath net.PercentageEscaper primitives.UnsignedBytes util.conurrent.MoreExecutors -1 -2 Readability as SO Readbility as MO

  14. Do users agree with optimization?

  15. Do users agree with optimization? 40 35 30 25 20 15 10 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 Optimized Default

  16. Readability post-processing • For a test t = <s1, s2,…, si> with coverage goal c we: • iterate over the statements in the test from the last to the first statement • For each statement we determine the possible set of replacement statements • For each candidate replacement t’ we determine if it still satisfies c • Tests are then sorted based on their readability score Foo foo = new Foo(); Bar bar = new Bar(“Some parameter”, 17); foo.setBar(bar); assertTrue(foo.isBar()); Foo foo = new Foo(); Bar bar = new Bar(); Bar bar = new Bar(); foo.setBar(bar); assertFalse(foo.isBar()) assertTrue(foo.isBar());

  17. Test Suite Generation • Test suites for all 359 top-level, public classes in Guava 2.25

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend