Trying to add Spek to an Android project.. I wish ...
# spek
c
Trying to add Spek to an Android project.. I wish I could get all the time back I have spent in the past few years diddling around with these insane build files.. will it ever be possible to create a project and get some tests running in less than a few hours??
😆 1
r
Yep there is and it’s planned for 2.x. We will provide our own gradle plugin (which will use JUnit 5 under the hood) for jvm and android projects.
c
Hate to whine about this but OMG I am so burned out on this thing.. I got it all to build the tests, but when I go to run it (inside AS3) it says that it cannot find the tests:
how can I paste an image into a thread??
r
So sorry about that. What version are you using? You might be experiencing this issue: https://github.com/JetBrains/spek/issues/248
c
WARNING: TestEngine with ID ‘spek’ failed to discover tests
is the message
yeah I looked at that thread
seriously a link to that should be in the first paragraph of the docs
like the sign in the inferno: ‘those who enter here…’
I mean I see a lot of bonfires, but that thread is super insane.. bleak
I couldn’t even follow it after a while
that’s from a while ago
I am using AS3B6
I added dependencies with the filtering
r
if you can paste the build I can take a look.
c
if you want I could add you to the repo
it’s on github
?
r
sure
c
ok added you
thanks Ranie!
I bet you will figure it out in minutes.. sorry, I have used Spek a lot of times before and have never seen this problem…
usually if the tests compile they run
(but have not used it in Android…)
r
Looking into it now.
I don’t see anything spek related in master?
c
oh wait!!
sorry about that !!
ok it’s there
@raniejade did you get it to build?
r
yep, testing out a fix. Looks like we need to update the docs. JUnit 5 gradle plugin doesn’t like android projects.
I’ll try it out with this https://github.com/mannodermaus/android-junit5
c
ok sure
changing to junit 5 is fine
I created the project with the basic AS3 template
the junit tests don’t run anymore either..
r
do you need it running as well?
c
no
just if I cannot get Spek to work
will have to use JUnit
I am putting together a Kotlin intro course
to convince a team that’s using J to use K
I think if we got into the setup and dropped into this smoking hole it would have been a short argument…
r
sure 🙂
looks like it’s more of kotlin - android issue https://issuetracker.google.com/issues/64804587
c
uh oh
r
pretty sure this was fixed in the canary builds
c
so should I just abandon all hope of getting this to work?
canary builds of Kotlin?
r
android
c
AS3 is canary isn’t it using canary K?
oh
r
trying out the canary builds
c
great
so basically the kotlin files are not getting copied during the build of the test target? wow…
r
yeah 😞
I finally made it work
c
no way!!
how?
r
I’ll create a PR.
c
fantastic!!
r
I would blame gradle 4 for this. hahaha
To make jUnit 4 work again, just add JUnit5's vintage engine to the test classpath
Let me know if it works for you 🙂
c
just pulled
I think I have your changes
getting the same thing
lemme double check but the build was a very long one so it was doing something new
r
can you run clean?
c
tried that then reran tests again
?
lemme try close/open
r
./gradlew clean test
ahh
wait your running it from AS right?
c
yes
oh crap
😞 same thing I just want to jump out the window
r
you might need to add a before run task for your run configuration
c
that’s 3 hours gone that could have gone into building something
r
wait let me try something
c
did you do that?
will I have to do that for each test?
yeah there was a Run Configuration already of course
r
can you add this in the root build.gradle
Copy code
subprojects { subProject ->
    afterEvaluate {
        if (subProject.plugins.hasPlugin("kotlin") && subProject.plugins.hasPlugin("java-library")) {
            subProject.kotlin.copyClassesToJavaOutput = true
            subProject.jar.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
        }
    }
}
then resync the project, delete any existing run configurations
c
dump that in the bottom?
r
yep
c
after allProjects {}
?
r
yes
c
got it
r
the initial PR was fixing the issue when running the tests via cmd line
c
WARNING: TestEngine with ID ‘spek’ failed to discover tests org.junit.platform.commons.util.PreconditionViolationException: Could not load class with name: com.tvcoursework.kotlinintrocourse.CurrencyTest at org.junit.platform.engine.discovery.ClassSelector.lambda$getJavaClass$0(ClassSelector.java:71)
yeah command line tests are a joke
r
ughhh
wait
c
Xcode was just rewritten completely and the tests just work and are blazingly fast
these guys all have ios and android teams so.. don’t think I can tell them to go back to the CLI… 🙂
ok waiting.. ?
r
can you add this dependency testImplementation org.junit.platformjunit platform runner1.0.0
are you using the Spek plugin?
c
yes
I have it installed
r
latest version?
c
just installed tonight?
but wait
maybe I installed the last stable one
which one should I get?
r
v0.4.3
should be the latest
c
yeah that’s what I have
ok so still same message ?
r
ughhhh
c
after adding the last dependency..
should I delete the Run Config?
r
yep please
c
nope same thing
r
hmmm
last
c
OMG seriously I don’t even remember what I wanted to build with these tools anymore.. I remember I was excited about it.. a while ago.. 😞
last?
r
going to downgrade to RC2
c
OMG who thought this stuff was ready to be used.. for all the hype K is getting right now, this is utter madness…
r
push something into master
can you pull and reimport?
don’t have AS 3.0 here, downloading it but it’s slow 😞
c
oh no.. wow
r
I have a copy at home, I can check this later
c
ok thanks I guess I will give up for tonight
feel like a whipped dog
r
I’m pretty sure I got a working android project at home using AS 3.0
c
this thing should have cones up around it
great
as I said
r
I’ll let you know
c
I did a brand new project
all I did was attempt to add Spek
you have access to the repo
hell I will make a donation to your Patreon page (if you have one) if/when this gets working
I don’t have tons more time to vaporize into this hole, have to prep other stuff… 😧
r
No worries, I’ll update you once things are working 🙂
c
I am still kind of confused about whether AS3 is required to show Kotlin on O?
should I just use 2.3.3?
r
I don’t have any idea, not an android dev 🙂
c
why cannot I paste a bloody image into a thread???
alright thanks Ranie
really appreciate your efforts
r
no worries 🙂
c
if you can make it work, will you send another MR?
r
yes
c
great thanks.. !
r
got it working (again) lol
but now it’s running in AS
PR sent 🙂
c
dude you da man!! great job!
OMG you will not believe this @raniejade it stopped working again and is spitting up errors.. completely insane..
I pushed you could take a look if you want, I think I am done with Spek, probably forever.. gonna try and just use JUnit….
r
I think you still have the same problem when using JUnit. Real issue is that classes compiled by kotlin are copied over to the directory AS expects.
c
so far junit is working
r
Interesting, hmmm. I'll take a look again.
c
appreciate your efforts
frankly the vanilla project does junit 4.x
but has hamcrest which is actually ok
r
My problem with AS they have a lot of hardcoded stuff for specific test frameworks. In fact the spek idea plugin, takes advantage of that. Tricked AS to treat spek as Specs2.
c
weird
r
sent another PR. This really annoying, kotlin and android integration really sucks in 3.0.
Pretty sure this was working w/ 3.0 Canary, was working with spek plugin at that time. https://issuetracker.google.com/issues/64804587
c
wow ok will try it
thanks again
you would think they would be taking K more seriously amidst all the hype
r
True, I think the problem is there is no or little coordination between the android and kotlin team.
t
seems like we are in the same boat
r
Ahh, shit. Sorry totally forgot about that ticket. I think I may have a fix.
@timrijckaert let me reply on the ticket.
t
Is the repo from @codeslubber somewhere public so I can check the config that is needed to get Spek to run in AS3?
c
@timrijckaert it is not public but happy to send you the gradle files, that’s all you need to see right?
t
yes
or you could show them to the world and help everybody https://github.com/JetBrains/spek/issues/256
m
I very interesting to see the gradle too 🙂
r
@mmaillot check the ticket 🙂
m
Thanks you ! 🙂
t
Nice this seems to resolve my issues thanks @raniejade & @codeslubber
c
Good to hear @timrijckaert
t
Maybe a good idea to update the docs to reflect a better guide on how to setup Spek with Android
c
That was one of the first things @raniejade said. To me one of the biggest problems in tech is that cones are not put up around open man holes so people fall in all the time. Probably in the future, there will be bots that will continuously estimate the likelihood that a chosen toe path will get you where you want to go without falling off a cliff..
r
I don't know why this hasn't been fixed yet, but it's kinda annoying that you have to tell android where the kotlin sources are.
Copy code
sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        test.java.srcDirs += 'src/test/kotlin'
    }
âž• 1
m
For me, the proposed code snippet doesn’t run directly from AS (
ClassNotFound
on
JUnit5IdeaTestRunner
) unless I also explicitly add the
android-junit5-embedded-runtime
artifact from the plugin’s repo. I’ll amend the issue with that, just in case somebody else stumbles upon it
Also, the android-junit5 aren’t setup completely in there. I’ll do some clean-up and remove the unnecessary stuff before we can attach it to spek’s docs!
t
Nice work it makes more sense now. I'm not at home with all this configuration work. I just wanna write a Spek test. Thanks for the steps in the issue. Maybe @raniejadecan add this to his PR