Coder Social home page Coder Social logo

Write Many Unit Tests about humbug HOT 4 OPEN

humbug avatar humbug commented on May 29, 2024
Write Many Unit Tests

from humbug.

Comments (4)

mbj avatar mbj commented on May 29, 2024 1

and then running humbug on itself

Because I like seeing mutation testing getting traction in other languages I'd like to share my story on this.

I faced a similar challenge with mutant to run the mutation testing engine for ruby, on itself. The moment the engine gets targeted on itself (or any of its dependencies) the results for killed mutations cannot be trusted anymore. Because you cannot easily decide if:

  • A mutation was killed by the test suite
  • A mutation was killed by a behavior change before the tests actually ran

Also some mutations led the engine to crash, before the test results could be collected. So instead to fiddle around with this rather fragile situation (it can be mitigated somewhat), to get a decent self hosting I created the "zombie mode":

This mode creates a dynamic in-memory self copy of mutant (and its dependencies) inside another namespace. I do this via tracing the requires, expanding the require against the load path, modifing the AST in-transit to duplicate the require into two semantic effects:

  • The normal regular one, as if require would not be hijacked, into the regular ::Mutant namespace.
  • A namespaced one to build up a 2nd instance of the mutation testing engine, the so called "zombie", into the ::Zombie::Mutant namespace. A dependency like ::Foo would move to ::Zombie::Foo.

Than after the engine is loaded I use the API from ::Zombie::Mutant to kill the mutations in ::Mutant. As the mutation testing engines code exist 2 times now (including a subset of the dependency tree that works nice with this approach), one side can safely mutate the other side, without the shortcomings of a self hosting mutation testing engine that introduces doubt to the result.

Also I'm now able to test dependencies, like AST transform libraries, unparsers, and other building blocks without that much doubt.

I have no idea if this strategy translates well to this project, but it might help to know about.

This post is naturally only 95% of the story, I omitted some ruby specific details, so feel free to ping me on any question. Happy mutating.

References:

from humbug.

stof avatar stof commented on May 29, 2024

and then running humbug on itself 😄

from humbug.

padraic avatar padraic commented on May 29, 2024

Of course ;). Your 85% that is probably over 90% is taunting me :P.

from humbug.

padraic avatar padraic commented on May 29, 2024

@mbj In very broad strokes, the approach would work in PHP also. The main facet is to basically have two copies of Humbug assigned to different namespaces where one does not impact the other once both are loading into memory. Achieving it in PHP would likely be a bit more ugly owing to how loading classes works in practice, and the difficulties in actually manipulating that dynamically (it boils down to one undocumented file access flag in PHP file streams of all things), but it's certainly doable.

Thanks for dropping by to suggest it!

from humbug.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.