How to Write Better Code Using Mutation Testing

Video in TIB AV-Portal: How to Write Better Code Using Mutation Testing

Formal Metadata

How to Write Better Code Using Mutation Testing
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Mutation testing is a silver bullet for assessing test quality. Mutation testing will help you: Write better tests Produce more robust code that better handles edge cases Reveal what parts of your legacy application are most likely to break before you dive in to make new changes Learn about features in Ruby and your dependencies that you didn’t previously know about This talk assumes a basic knowledge of Ruby and testing. The examples in this talk will almost certainly teach you something new about Ruby!
Web page Machine code View (database) Projective plane Branch (computer science) Machine code Line (geometry) Measurement Numerical analysis Statistical hypothesis testing Process (computing) Computer animation Different (Kate Ryan album) Quicksort Bounded variation Window
Ocean current Machine code Computer file Multiplication sign Client (computing) Function (mathematics) Parameter (computer programming) Disk read-and-write head Twitter Statistical hypothesis testing 2 (number) Codierung <Programmierung> Social class Form (programming) Scripting language Sampling (statistics) Entire function Numerical analysis Message passing Process (computing) Computer animation Query language Network topology Universe (mathematics) output Right angle Resultant
Statistical hypothesis testing Computer programming Electronic data interchange Inheritance (object-oriented programming) Projective plane Letterpress printing 1 (number) Motion capture Function (mathematics) Parameter (computer programming) Student's t-test Statistical hypothesis testing Revision control Type theory Mathematics Computer animation Personal digital assistant Videoconferencing Representation (politics) Right angle Table (information) Resultant Social class
Statistical hypothesis testing Group action Machine code Multiplication sign Parameter (computer programming) Mereology Dimensional analysis Medical imaging Mathematics Sign (mathematics) Different (Kate Ryan album) Error message Social class Area File format Digitizing Electronic mailing list Bit Variable (mathematics) Data management Arithmetic mean Hash function Order (biology) output Right angle Quicksort Resultant Game controller Implementation Service (economics) Divisor Electronic data interchange Data recovery Motion capture Branch (computer science) Rule of inference Statistical hypothesis testing Twitter Revision control Natural number String (computer science) Task (computing) Condition number Addition Multiplication Matching (graph theory) Validity (statistics) Key (cryptography) Prisoner's dilemma Weight Expression Interactive television Database Line (geometry) Numerical analysis Word Uniform resource locator Nationale Forschungseinrichtung für Informatik und Automatik Computer animation Personal digital assistant
Dependent and independent variables Email Key (cryptography) Multiplication sign Client (computing) Distance Performance appraisal Process (computing) Computer animation Hash function Atomic number Repository (publishing) Right angle Object (grammar) Resultant
Statistical hypothesis testing Addition Machine code Service (economics) Linear regression File format INTEGRAL Execution unit Control flow Machine code Distance Checklist Mereology Measurement Statistical hypothesis testing Word Message passing Computer animation Personal digital assistant Different (Kate Ryan album) Authorization Quicksort Form (programming) Condition number
Area Computer programming Complex (psychology) Scaling (geometry) Machine code System administrator Sampling (statistics) Online help Statistical hypothesis testing Computer animation Internet forum Personal digital assistant Different (Kate Ryan album) Authorization Ideal (ethics) Boundary value problem Right angle Text editor Condition number God Physical system
Email Mathematics Computer animation Personal digital assistant Order (biology) output Iteration Function (mathematics) Quicksort Standing wave Abstraction Statistical hypothesis testing
Statistical hypothesis testing Machine code State of matter Design by contract Propositional formula Water vapor Function (mathematics) Parameter (computer programming) Disk read-and-write head Medical imaging Mathematics Estimator Different (Kate Ryan album) Endliche Modelltheorie Physical system Area Theory of relativity Mapping Point at infinity Moment (mathematics) Binary code Sampling (statistics) Shared memory Instance (computer science) Variable (mathematics) Substitute good Category of being Process (computing) Chain Normal (geometry) output Right angle Quicksort Resultant Point (geometry) Twin prime Similarity (geometry) Drop (liquid) Event horizon Internetworking Reduction of order Integer Condition number Form (programming) Default (computer science) Noise (electronics) Greedy algorithm Dependent and independent variables Information Weight Line (geometry) System call Word Computer animation Integrated development environment Personal digital assistant Iteration Library (computing)
Statistical hypothesis testing Optical disc drive Machine code Computer animation Personal digital assistant Right angle Object (grammar) Statistical hypothesis testing Social class
Presentation of a group Game controller Machine code Direction (geometry) Device driver Branch (computer science) Open set Parameter (computer programming) Checklist Distance Proper map Statistical hypothesis testing Workload Medical imaging Mathematics Average Different (Kate Ryan album) Reduction of order Endliche Modelltheorie Traffic reporting Initial value problem Task (computing) Default (computer science) Matching (graph theory) Arm File format Weight Interface (computing) Expression Interactive television Counting Line (geometry) Machine code Cartesian coordinate system Regulärer Ausdruck <Textverarbeitung> Process (computing) Computer animation Integrated development environment Personal digital assistant Normal (geometry) Quicksort Resultant Reading (process) Lambda calculus Row (database)
the my mind here and
I want my name is John then we got new about the mediation does under CTO at us for the company and all called upon know I and so there's also flickering year graduate on but our so before you know it only view without 1 . I we an introduction to what it is just a is century out of your improved does coverage the that show you how can I teach more about Ruby included you rely on Montreal can be an x-ray for going the code How do we have great tools for detecting dead code the out the probably the most thorough measure of test coverage having helped divide code than the other but optimum practicality is destined to and how can corporate I and a job the so before does not reduce the average window the same page for blind coverage or test coverage in general using retirement test coverage women on coverage so when coverage roughly means that number 1 2 primary over the total lines occurred in the project different variations of that branch coverage and that sort of the adjustable edition is the US it from questions that says but how much of your code can change without knowing that but the thing about that makes sense I if I can remove 1 of total war me we modify a 1 of coding of projects add whenever you destined for the 400 ms industrialists and code so before we actually had died and you have to automatically you know the tool to reduce the strain on view that into which of of what we do is just is by doing it by hand so I some
sample code here using read over the in so that it was a class called gluttons them at the top of head and is initialized with Twitter client then I research on the tree EPI using a client i and ii the 1st 2 results but the other thing and that that these were the test that's present here it's got a I think client and and some big tweets to but on the left here I've got had the same code that and sublime text on the left and the right of edit script is when to run your modify the file messages on output it disfavor of code against the current output or that the current OWL code and someone text as well as the the result of the test so 1st time going to go in and try to modify the hashtag that does not tell the test I'm also removed assertion entirely that village the and magnetic always 0 argument from that also not build that if I change the 1st 2 the first one that those films that that's good emerging diverse query that is not the test the at going
over those again they basically change the input to the search method however 1 can remove the hashtag for the entire search trends Call it with the number of arguments the matter if I change the 1st universe 1 that is below that is regular has had to fake tweets an API Client the but the 1st 3 and that is not with us that is we only have to think we can attest FIL that's manual dish Justin I imagine doing that actually did a better job of the pretty tedious had the of your this is 1 method but were adding ongoing decoding can do this for a reason for that had because the routing would be there are a lot of wasted time at and it's also pretty hard outsmart itself it is to the best again can I bring this code and ready to test for it then it's in me harder than 30 seconds later recalled what things did and they have a form I now show
you how to conditions as and what they automated tools others I had a main tools this is called mutants that's been around for years but I 1 about about 2 years ago out and it is testing pardon and since then the by origin project if n I also started a for this project recently for the test I had that as print 3 moral right now known as the representation of what we refer to them interchangeably but you can use it other 1 right from table and by invoking
the mutant but men on argument the minimal and and program and the of flight St. used off with integration and tonic to mutate at a class we just saw there's a new isn't output tonight way about it will go over all that a revolt against it's death here is a mutation the bound after a while running my test so the bound some things we also banner manual revision testing run they can remove inherent in this matter it also pointed out that we invest in a different type of the variable to the search results doesn't know which chance so they wouldn't capture In our manual run is-a contain change 1st to the last and of this is the reason that the by most recent that between than others but we bring that change if we care about 1 of most recent we I would go toward a return the oldest ones it also removed the 1st to call entirely wouldn't change we go specify avenue to because of each of is good abduction and another student there the video possibly quickly exhaust are had EDI token rely on ourselves so in this case army dishes and tool shows us how to improve the test we have a 3 they create incentive to and we also expose was that's by the church to expected to perform so we use
have the tested automated it's quick and we don't think were extend much more effort and it's going to be more clever the need to add MIT has been occurring in different politicians 3 years that alter reverses of use cases and try to point out that artists of changes but in encoded as interact with so the another example in this case and you don't have to work on an internal API this example of using a reader the the it whole so here we have a users controller in that show actions the working in the IT planner made sure that the manager doesn't use refinery and either rendering adjacent for all we found or error in the primitive the test closest run the throne additions and tool to a
chosen replaced the other 2 I met for the uppercase and German that such a branch and add up to the the difference the 2 I met them or any string and I know if I don't have any images writing digits in my strange history me 0 because I know it's in in the 0 it another generates novel even know and so on prisoner if it can't I get a number out a string results also in change the the hash cracker but there to hash fetch and a difference there is all the more strict on presence of the key so had and there's all conditions if the ID he was not there this is our return no now this code between reason area that he is the so put together are tools Boston to write a short slightly more strict implementation of this action it's saying that a certain presence of the key that that of the ID value actually are possible as an integer and as as a mention implications to word for my own are probably better for example before if someone use EDI incorrectly something or did not pass in the ID than we would try to get the we can now be ported to 0 method to the Finder and return the user error saying cannot find user with the 0 add a close look a bit more they are well fitted of mentation for this problem and I were also being forced to think about things like not performing extraneous that database queries instead of had been validation at a time use of a small example in this case we a but created action all when here read over white it whole so in this case were passing a parameter called after if it's in a path that input and opacity to a class that that on recall reasons the it we run this through the tests and show us that natural place parts with another called ISO into so 1 Rafaelia the different as a k 2 pretty pro-Indian method but basically it's a more strict passing physically at best buys this before but this year adapts to for the month attached to digital today and this is pretty sniffing compared to be add person rules for data part it this and try to do but it it can pass input to 100 for all these different formats as well as and when I know what parts of the finds the name of month inside the and and but then it's going to pass and so on unlikely that every valid input now were May 1st that's something on the right we have all the input to can produce may 1st to the 17 at now recovery you expressions the I'm particularly excited about this rendition because this is out a feature that I think no other tool in the ecosystem can really help you with that Newton and the test and are actually begin to regrowth Russian and show you of the Directorate branches within a reciprocal here's a maximal code this year we are entering over he had list of usernames them with an array of strings and worse like in 1 dimension this rigorous version the person when see here is a contingent of replace the car and the dollar sign with that sort of say and that's what the at and that's enough for the different the carrot and offline been beginning and end of a line whereas the backslash of this a and that such mean beginning and end of string so in the 1st case I did pass in the Alice new 1 John we Bob broadmatch and the Chinese in this case they don't provide any test input that shows that you want an abysmal doing trends thought have to change this to more strict format and also works it's also try to remove each other value in the alternations and of make sure were at testing each initial is inside recession were actually saying John or Alan are both out matches so Schmidt Hessen locations is also going to try to put a question mark the pull under the the by ends that means addition into a passive basically dependencies INRIA expressions for multiple purposes they can both be a mechanism for aggregating expressions like here we have the pipe were saying John or but also means the that but we want to extract this value and others are matches so in this case the opera Mark means but we don't care about extracting value were just group and services is recommending that we either task of captures something or I use this more intentionally instant access and finally were running this on to run for the 20 say use the new match predicted at the and it upper the difference of this method is nudity 1 for about 3 times faster army returns are true or false and the weight factors that doesn't do anything with I global variables where that every other illustration of the ball actually set variables regardless of whether you want to and you put all this together we get something that is more certain input better tested 1 tension dealing with the passive country and more performance the whole thing here is that we never know about entities features and Ruby in order to write this method role when you and the tool recommended all these changes which resulted in every different method but for task right
now I'm going to talk about is the clients here we got
a method called stars form or just using the popular into be party that client 22 taken a our repository named the time into a hatch and then get the key under the starters count runs from distance and all were see at the where did I can remove the 2 h atoms that and so works as etymologies and using 1st but what's going on here is that issued by the client actually well within the contemplate response header and the evalu hash bias the responses Jason and I have a whole reaction that to each of and interactive response out of that object to so we were before our hands were sustained and the cool thing here is that that we just as not have any of the by specific it http party had like support for that is knows how to walk through your mother definition and removed from and so as a result In written notice before France's mutation read the documentation and up there and we went over the more the process the right now the legacy
code this is the same codes and we have the form other the
creator and when we're passing and the In this case the United that instead of art and when this method yourself you're being tasked with updating method but maybe I news future and means more realistic but say that the review author but it 2 years ago there is much that condition that on a few tests and that they longer this company when you run your additions into on this code before reaction modifiers here see this addition to i so it's the 1 they don't know it then you on the part of the documentation to with differences perhaps the more should the person format and this is what this leads to us asking a few questions about the code question was the others in 10 years the they mean for people only use this very strict format or did they mean of will be we use any format is not test for that more importantly because could actually use that if the other services that passing other formats here repel 1 Ashley updated Itar-Tass reflect weak support this break down the integration and a running distance into all understood before we modified 2 must be are checklist basically of things questions that we should enter before modified I In other words is basically units sort of a white list of hotspots where if we modify this part we would actually I into a regression and the test won't fail the full isn't too surprising but mediation testing can be a very thorough had way to measure test coverage consider this but the
idea if we in both that all within or our program then God a white of rituals when say that we have the coverage but even we doesn't directly we're still probably not present in the ideal way army teachers and tools and show us that actually that old boundaries here and say they are you actually testing for off by 1 areas here to say do you have a tests that's fine 21 as the minimum age for my all 120 is rejected 20 is allowed in the film of the boundary it actually helping us improve our test and this very for a modification of the code I had can give very big help from where we are dealing with very complex methods that seem pretty simple this is only 9 1 that that here but in this case and we're doing a lot of places this we have met year deciding whether a given user and system called editor here In an even post Mr. different user roles yeah the modify each 1 of us Canada each individual token additional ask us are you test the case where the user is a gas what I needed 101 the normal user and they are the author of a post what poses a lot right as his conditions together when the the editor is the other the post and which locked think additional is not what not the other locked when when the moderator protesting the condition where the author is and is not an admin right it is the case for the inhabitants this may seem like like large amount of test to be running for this reason method but many dishes and tools will be closer to the actual complexity here the thing about it the editor of the Post have 5 different roles on the scale not enough roles and we also the case for the editor is or is not the user had trying to edit books the the finally at admission where the the post is original what tragedy on
with a 31 of emissions yeah there's a lot complexity and are use in tool is at least forcing us to embrace how complex it is and actually prove that all we are controlled is emissions is that a small sample
in this case I'm taking was the users and I had not been over them and then we know that delta and user that either don't have any mail order previously unsubscribe anomalous this the sort of those they're usually right to test how we just saw In the 1st example we've got a valid user and then a user without the now norther in that the value 0 e-mail as would be the output and the 2nd is a standing wave about user and abstract user and worsening upon the values using all and adjust our obligations and tools China has a real chance next to break here as pretty but makes sense given the ad test that we wrote FIL back them that In each case we have the invalid user or the user to return filter out at the end of our test input so in this case skipping 1 iteration is the same as ending iterations and so in this case the way practice tests is to put the user the lowest at the beginning and how the are the and this is not a small change in the
test they'll make galveston protest the the
dishes has also a great tool for detecting dead code consider this is a word In the rails and I
don't know that I matrikas do for me if I have a column called name if I don't know this run dishes into 1 she shown here that replaced and that the body was super the model at 1st what it's saying is that the entire condition not that sorry covered by the contract so In other words and use the rails I not a redefinition and had gotten any co-workers workers to discover that and and using a reduction method and here's a another example right that the person for aid medical authorized an optional argument for the user the public on user if the usage looks like this there's final mutations was you're always passing the user so the but the usage of the best changes in different and try to apply the previous annotation and it is a felt as we are calling was 0 arguments and so the twins say they are the this assignment and put it the internet the body the other words no matter what you pass the override a local variable what the value on user the In other words values user static here and we can actually is in line producer and that it would not entirely this is a very small feature that actually do what the survivors of an into it on William refactoring I have described elsewhere metaphors qualify conservation at and later moved it into another my desk and often adopted concept the well the just show us that we replace called for my out with nothing to remove it I use 3 inches and say actually somewhat askance reference and same them is a small sample In this case we are passing and ID parameters and for point 8 the post fire binary response and communicate to be set is a 200 into new dishes and tools a show us that we can actually lose that status OK entirely and look at the definition makes sense in this case the default status is going to be 200 Fig and broaden all the more about the real for us but I ship net result mediation or 1 coworker the similar to the head dead code the sodium it is just and also a great resource for possible here's about the women have that ensure this were and these are disparity resembling array of integers finally user finder hence 1 input since they are actually the spot here his passing ability the same again we're on all the more accurate than face and it's and basically 0 past here we have used that greater at the top we haven't actually reader for the user and the greedy method has returned often than in the user this is an instance variable the mutations indels and show us that we measure place the user answers variable with the user method this is a very small chamber they're showing a lot that he had actually land use and also the method called has nice properties we don't do it in some variable we tabled as variable for example you know and we so the more cryptic area but if we tie method calls when you have sort of more clear they're saying that we tabled and then in this moment that were that were best finish training which is a patronymic system the leading and there were replaced leading tell them what the value of the home environment variable when this through the testing shows a replace g somewhat some which makes sense we only a global substition here the 1 substitution so it's recommended to us that we use the more intense reviewing on specific but sub pejorative once a petition here's another example the relative Privad noise it we have the sort of method I had if we were familiar images where In delay job is something we are i . i really look for images and Due to the last 2 years the iterate over all of the debug output and then do it all and return the gap wall between shows here we can remove the map with and ways of each In a sense not airing over this input and our referring indirect I said so in this the norm or each other this to what 1 that isn't that were previously but I was mapping of the input and returns a new in Riverton where else and that change of back to and each and the nice thing is I don't have to always worry about menus on the states the I don't we just touching then finally here's a I the small example where I'm using a reasoner library water and I am I had 34 matter which isn't it information about it all events and are take the different data their prior shrink and then that'll be what ought to be add up the chain here now we just initial estimate after place this property land is it a pre similar so these are forget what the actual differences here but using this very simplified example here we Proc that takes into arguments on the right and etc. now they call this the proposition I can call no and the by 1 argument your experience does matter which is your into when you that fall that are in no and if there's too many areas in sound drop them and that share the same behavior for thousand right between the thalamus splattering and then behave the same as form but we use a lander these old words a noise so you think now
that for 1 we were especially if I'm editions that involve all ridiculous by usually the odds of 101 ones along and of my testing our strong so having possibly be practical well there's a few features that make this more manageable 1st takes and a sense why
we investigate revisions and that these those only did code that is changed since this idea provision so in this case if we have 2 minutes bisons master from this like that code that ashamed that shipments you know Sebastian they test selector which is like this constant name and then I add a method and that same and the my giant object right hands I only change 1 thing from did that and also understand lost the conventions so it is describing class and spending about that the Duchy only on a select for mutation that small method that year had or 2 before it is only a select the dozen tests that actually past this might be the at the so the dishes and I think has been 1 of
most powerful sources of growth me last few years and I think they're not using the distance and then then it will be brought to of 2 or more about reading there's dozens and dozens of special case mutations that are based in the tool that only show up when they apply different tasks the and so you sort of wonder about a just times some examples in this presentation are how it changed it apart size so it's it's it's a 1 all this in regular expression features the new feature of the new match feature and will be doing for for Rio expressions and also proper lambda and change and the generalized use that makes the removals of no lines of code or arguments you pass into a method or arguments those of you walk on more about for the if rely really surprised at how frequently this actually voting on and new so these emotionless are how we worry about how it should be it should be party that is if only if the commentators application J. Sun was all the different the ideas that we see from but different rails but things like the control behavior with a default telescope and act records of interface the and the net result here is not just the 1 more but the also on all the Baxter was that might every do work every you do is add 4 add code you're going also be 1 over 1 . ruby on average and on over more that could the interact with the Suriname find that at the and it's obvious you know I review doesn't skills a certain things more about that where all branch of that what happened here and but what actually is the have expected behavior of this feature nematic but net result here is you end of model here but understanding of the code all the better and you end up shipping your body steer understanding what Tessa still not doing anything or what what the test is not being tested there that currently moving but unnecessary coding using more simple ad methods with reading and if you do this had the dishes thing on code before you modify and new unfamiliar with that the following introduce your reference as image before you get sort of a white list of hot spots in the application that are likely to allow you to break the code without going to test norms open reduction and this a sort of checklist of white for a change this I need understand is someone suppose on passengers the format or are people now using it in different ways result in writing some code some ordered dead code that conventional for you're going to the surprised by yeah removing a few lines here some of environment a medical here using it and work I really method or but on the other as drivers of workload and so much every 2 arrived at after an initial condition the so I hope I was some you are excited to use reduce does have a job now if you're coordinated excited about I using as a team you so using it as a report I if you do so your problem are all the more about Ruby over more about 250 depend on here the task and appointed grow over Vassar their coworkers and if you're watching lead is consider the test is here Seattle yeah obtained from sanitation coverage started benefit here just the that what could you change or that they wanted test is a powerful tool both author and reviewer the food offered better but some review themselves and ask judges to report ship this and from this you don't have to deeply understand tests code involved like as much more to understand is a city of direction they know always so that's the i've and think is this but what what what the modifications will make here I have there a bunch new which that's more that's if you it decided a and you over in great tho we should you know us jobs according to its you don't count and I hope that you all are excited about using distance and there's a the
arms so