# ANN: MethodInSrc.jl ; verify that your method is invoked

**URL:** <https://discourse.julialang.org/t/ann-methodinsrc-jl-verify-that-your-method-is-invoked/18487>\
**Category:** Tooling\
**Tags:** announcement\
**Created:** [December 9, 2018, 12:22pm UTC](https://discourse.julialang.org/t/ann-methodinsrc-jl-verify-that-your-method-is-invoked/18487 "2018-12-09T12:22:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [December 9, 2018, 12:22pm UTC](https://discourse.julialang.org/t/ann-methodinsrc-jl-verify-that-your-method-is-invoked/18487/1 "2018-12-09T12:22:37Z")

</div>

> **[GitHub - jlapeyre/MethodInSrc.jl: Test whether a call is dispatched to a...](https://github.com/jlapeyre/MethodInSrc.jl)**
>
> Test whether a call is dispatched to a method in your module - GitHub - jlapeyre/MethodInSrc.jl: Test whether a call is dispatched to a method in your module

Example: Test that `sum(m)` uses a method defined in the module I am testing, but that `prod(m)` uses a generic method:

```julia
@test @isinsrc sum(m)
@test ! @isinsrc prod(m) 

```

Example: Test `sum(m) == 1`, but throw an error if the method invoked is not in the module being tested.

```julia
@test 1 == @insrc sum(m)

```

I have needed this for a while, so I wrote it yesterday.

---

<div class="post-metadata">

**Author:** ![jlapeyre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlapeyre/32/4514_2.png) [@jlapeyre](https://discourse.julialang.org/u/jlapeyre)\
**Post date:** [December 9, 2018, 8:01pm UTC](https://discourse.julialang.org/t/ann-methodinsrc-jl-verify-that-your-method-is-invoked/18487/2 "2018-12-09T20:01:33Z")

</div>

Kinda sorry for bumping my own post, but it occurred to me that the motivation might be a bit mysterious. So I added a motivation section in the README. I reproduce it here.

## Motivation

Some code provides efficient, specialized methods for particular data types. It’s important that the input, the output, and the function call look exactly as they did before implementing the efficient method. So the test shouldn’t change:

```julia
@test sum(A) = n

```

How then, apart from benchmarking, do you test your new implementation ? This module is a step towards a solution.

The problem becomes more complicated, and more error prone, if you have a file defining binary operations, say multiplication, for combinations of various particular and abstract types. Are you sure dispatch is occurring as you intend ? Furthermore, due to changes in other code, someone may remove a specialized method that has become redundant, or add a new one. When reading this code (even if you changed it yourself last year) and you can’t find method, did it go missing, or was removed intentionally ? _“… wait a minute, there’s a test for that missing method in the test suite, and it’s passing!”_  
You get the idea.
