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

Mixing MockFactory into AsyncFunSpec results in empty test suite #156

Closed
jgraniero opened this issue Nov 7, 2016 · 15 comments
Closed

Mixing MockFactory into AsyncFunSpec results in empty test suite #156

jgraniero opened this issue Nov 7, 2016 · 15 comments
Labels
Milestone

Comments

@jgraniero
Copy link

scalatest 3.0.0
scalamock 3.3.0

Hoping there's some workaround for this or I'm just missing something.

I've tried running the test a few different ways. It seems like Intellij and Gradle are both reporting an empty test suite.

class TestSpec extends AsyncFunSpec with Matchers with MockFactory {
  describe("A test") {
    it("should do something") {
      1 should equal (2)
    }
  }
}

If I replace AsyncFunSpec with FunSpec the test fails as expected.

I also found this issue over in the scalatest repo. Not sure where the problem lies, though I can confirm that the "async" specs work fine so long as MockFactory isn't mixed in. If you find this is an issue with scalatest, I'm happy to go give them more context on the issue I linked.

@jgraniero jgraniero changed the title Mixing MockFactory into AsyncFunTest results in empty test suite Mixing MockFactory into AsyncFunSpec results in empty test suite Nov 7, 2016
@barkhorn
Copy link
Collaborator

still an issue in 3.4

@barkhorn barkhorn added this to the v3.6.0 milestone Jan 22, 2017
@barkhorn barkhorn added high and removed confirmed labels Jan 22, 2017
@evictor
Copy link

evictor commented Jan 23, 2017

Any possibility of a workaround for scalatest 2.2.6?

@evictor
Copy link

evictor commented Jan 23, 2017

I came up with a workaround that, though not ideal, does at least allow running async tests with mocks, e.g.:

object MockHelper extends MockFactory {
  val fooMock = {
    val fm = mock[Foo]
    (fm.bar _).expects()... // etc.
    fm
  }
}

object FooTest extends AsyncFlatSpec with Matchers {
  // normal async test with reference to MockHelper.fooMock, etc.
}

@barkhorn
Copy link
Collaborator

@evictor thanks, that's useful info.
On scalatest 2.2 support: ScalaMock is now built against Scalatest 3.0 for new versions, so I can't guarantee it will work with anything older than that.

@smrnv
Copy link

smrnv commented Feb 13, 2017

+1

@daniel-shuy
Copy link
Contributor

+1
Still an issue in scalatest 3.0.1 and scalamock 3.5.0

Intellij/SBT do not even report it as an issue, the tests just do not run. Removed with MockFactory and it immediately works.

Thanks @evictor for the temporary workaround.

@daniel-shuy
Copy link
Contributor

Just discovered there's AsyncMockFactory for AsyncTestSuites. Tried it and it works (at least for my current use cases). This issue should be closed.

I noticed that there are some ongoing issues for AsyncMockFactory. Is that the reason for it not being documented (still experimental?) in the Readme and/or User Guide? If not, I might be able to help update the documentation.

@barkhorn
Copy link
Collaborator

Hi @daniel-shuy
AsyncMockFactory is pretty recent so it is not in the documentation yet.
Glad it works for you!

I have changed the documentation over to use the builtin Jekyll process of GH pages, and a pull request against the gh-pages branch would be very welcome, especially with some nice Async examples if you got any :) 👍
Just add a new markdown file in https://github.com/paulbutcher/ScalaMock/tree/gh-pages/_user_guide

@barkhorn
Copy link
Collaborator

@jgraniero @evictor , could you confirm this as well - can we close this issue?

@evictor
Copy link

evictor commented Mar 1, 2017

I'm on version 3.0.1 of scalatest for Scala 2.11 and do not see AsyncMockFactory. I can't remember why I was stuck with this version rather than latest but yea I did have to carefully choose this version. :P

@barkhorn
Copy link
Collaborator

barkhorn commented Mar 2, 2017

@evictor can you try using ScalaMock 3.5.0 please? AsyncMockFactory is part of that.

@evictor
Copy link

evictor commented Mar 2, 2017

Roger. Sorry, yea, I was using 3.4.2 of ScalaMock. I changed to 3.5.0 and codebase seems to be working fine with the new AsyncMockFactory. This is actually an open source codebase; changes can be seen here (for posterity): https://github.com/GravityLabs/gdk-scala/commit/d0bc814a8b1ed2d23bb4fcfb8aebe27b0c1b7135

@barkhorn
Copy link
Collaborator

barkhorn commented Mar 3, 2017

Thanks for confirming this!
with ScalaMock 3.5.0 you might be able to avoid constructs like https://github.com/GravityLabs/gdk-scala/blob/master/src/test/scala/com/gravity/gdk/util/http/MockableHttpRequest.scala as well, as it now tries to fill in constructor parameters automatically (not all cases work yet, e.g. type parameters, see #170 ).

@barkhorn barkhorn closed this as completed Mar 3, 2017
@evictor
Copy link

evictor commented Mar 3, 2017

Thanks!

@poohsen
Copy link

poohsen commented Dec 20, 2017

I see this behaviour with
scalamock 4.0.0
scalatest 3.0.4
sbt 0.13.16 - 1.0.4

The workaround posted above works for me.

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

No branches or pull requests

6 participants