mardi 29 janvier 2019

C++ Testing with describe-it

When working with Node, I like to use libraries like Jasmine, frameworks like Mocha and Chai. But so far, the only way I tested my C++ code was to construct little programs in single files, build all of them separately and run them, and see what their exit status is. Though, I am very sure there is a much nicer, cleaner way to do this.

I looked at Google Test and a few random ones at Github, but I couldn't see where a test is ever really described, like you'd do in describe() or it().

Essentially, I'd like to do something like this in my C++ tests:

int add(int a, int b) {
  return a+b;
}

describe("the add(int,int) function", {
  it("should add two numbers", {
    int c = add(1,2);
    expect(c)->toEqual(3);
  })
})

This is obviously some concept code there, but essentially what I would like to do. Do frameworks for that exist - and is there one that does not require C++11 (which I'd like to avoid since MSVC is not very well on supporting that unfortunately)?

Aucun commentaire:

Enregistrer un commentaire