GithubHelp home page GithubHelp logo

craftytrickster / mock_me Goto Github PK

View Code? Open in Web Editor NEW
44.0 44.0 0.0 24 KB

MockMe is a tool used to mock dependencies / function calls when running unit (lib) tests in Rust.

License: MIT License

Rust 100.00%
mock mocking rust

mock_me's People

Contributors

craftytrickster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mock_me's Issues

perhaps can work after all

if the mock_me_context lookup was made to have multi values (perhaps the value can be the name of the test_fn, etc), instead of a single key -> value, perhaps we can avoid the issue of tests clobbering each other.

#[inject] is not thread-safe

Repro step:

  1. Make sure your CPU has โ‰ฅ2 cores.
  2. cargo test --test test
  3. The test will fail most of the time.

The problem is that test_with_silly_func_1 and test_with_silly_func_2 will both modify the same _mock_me_test_context_instance. Now imagine the following sequence:

Thread 1 Thread 2
_mock_me_test_context_instance.set(replacement_1)
_mock_me_test_context_instance.set(replacement_2)
function_with_fun_id()
_mock_me_test_context_instance.get()
Finds out silly_func becomes replacement_2
Computes replacement_2(30, 20)
assert_eq!(600, 10)
๐Ÿ’ฅ

Tested with mock_me = "0.2.2" on crates.io.

$ rustc -vV
rustc 1.21.0-nightly (e26688824 2017-08-27)
binary: rustc
commit-hash: e2668882406b68739c6ed33d420358d5d710e67b
commit-date: 2017-08-27
host: x86_64-apple-darwin
release: 1.21.0-nightly
LLVM version: 4.0

Infer the function signature when mocking a function

Currently, we are forcing the programmer that is mocking the function to write the function signature. I would like this to be inferred automatically. I am not sure how this can be done, perhaps scanning the source code itself for the function could be a (somewhat crazy) viable approach.

Add spy/stub like ability to mock

Add ability to lookup which args were passed to mocked function in order to confirm test went through, as well as the ability to see how many times it was called.

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.