Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It should be possible to run a single or selection of tests instead of every test in a file #29

Closed
peterklijn opened this issue Oct 3, 2016 · 9 comments
Milestone

Comments

@peterklijn
Copy link
Contributor

peterklijn commented Oct 3, 2016

When writing unit tests in plain old JUnit, at least in an IDEA it is possible to run a single test. Currently this is not the case for oleaster afaik. Now I understand that this is partly an IDEA thing and this might be seen as out-of-scope for this project. However I would suggest the following:

In Jasmine they have the 'focused specs' concept, where you can prefix an it with the letter f, to run only that block, or prefix a describe with the letter f to run only that describe block.

Focussed it

describe("The Product class", () -> {
    fit("should be awesome", () -> { // <-- only this it will be ran, every other will be skipped
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    describe("nested thing", () -> {
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});

Focussed describe

describe("The Product class", () -> {
    it("should be awesome", () -> {
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    fdescribe("nested thing", () -> { // <-- only the it's in this block will be ran, every other will be skipped
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});

An interesting alternative, which I prefer since it's more readable, is Mocha (which is a Jasmine alternative), which used the 'exclusive' and 'inclusive' concepts:

exclusive it

describe("The Product class", () -> {
    it.only("should be awesome", () -> { // <-- only this it will be ran, every other will be skipped
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    describe("nested thing", () -> {
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});

exclusive describe

describe("The Product class", () -> {
    it("should be awesome", () -> {
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    describe.only("nested thing", () -> { // <-- only the it's in this block will be ran, every other will be skipped
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});

Inclusion

describe("The Product class", () -> {
    it.skip("should be awesome", () -> { // <-- run everything except this it
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    describe("nested thing", () -> {
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});
describe("The Product class", () -> {
    it("should be awesome", () -> {
        Product p = new Product();
        expect(p.areYouAwesome()).toBeTrue();
    });

    describe.skip("nested thing", () -> { // <-- run everything except this block
      it("should do 1", () -> {
        expect(true).toBeTrue();
      });

      it("should do 2", () -> {
        expect(false).toBeFalse();
      });
    });
});
@peterklijn
Copy link
Contributor Author

@mscharhag, can you please respond?

@brunodles
Copy link
Contributor

@peterklijn you can create a static method that simply ignore the methods.
Take a look here

@marioplumbarius
Copy link

marioplumbarius commented Apr 2, 2017

@peterklijn don't know if this is the case, but there's another project from the community under heavy development and which has all those features you need.

https://github.com/greghaskins/spectrum

@peterklijn
Copy link
Contributor Author

Thanks for the tip @brunodles, I actually already implemented it a while ago :).

Just added a PR a few seconds ago: #35

Thanks for sharing @marioluan, however I must admit that I'm not the biggest BDD fan. Hopefully my PR will be merged 🤞

@mscharhag
Copy link
Owner

Good suggestion. Thanks for the pull request @peterklijn. I will have a look in the next days.

@peterklijn
Copy link
Contributor Author

@mscharhag did you have a chance to look at the PR already? Is there a way that I can help to speed things up a bit?

@mscharhag
Copy link
Owner

@peterklijn I am sorry that this took (again) longer than expected (which has nothing to do with your pull request). Does it help you, if I create a new release with this pull request?

@mscharhag mscharhag added this to the 0.2.0 milestone May 15, 2017
@peterklijn
Copy link
Contributor Author

That would be great! Thanks

@mscharhag
Copy link
Owner

Added 0.2.0 release containing this and your other pull request. It also available via maven central repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants