one of the most compelling uses of Kotlin is for u...
# android
c
one of the most compelling uses of Kotlin is for unit tests, but after spending hours on getting Spek to work in a vanilla project generated from AS3, I need to move on, found an article about using JUnit where the tests are written in K, is that a good approach? is there a better source than this? https://fernandocejas.com/2017/02/03/android-testing-with-kotlin/
d
I wouldn’t try using anything other than JUnit (or something built on top of JUnit) for Android testing, I don’t know the details but there seems to be some kind of “most favored” status for JUnit on the platform.
c
Thanks. I am just coming to that conclusion. I am surprised that they don’t even have JUnit 5 in the AS3 templates? what on earth? and at their developer event a few years ago Google admonished devs for not writing tests!!
Make it easier if you want people to do it. They did in ios. There is zero fuss there now and the tests run at ridiculous speed..
d
Only JUnit 4 has the “most favored framework” status.
It was JUnit 3… 3 years ago maybe? There’s something that happens during the build process which makes it possible, but I don’t know the details. I think most Android developers who are interested in testing, aren’t happy about the level of support provided.
(This is ignoring that in my opinion, many apps can be reduced to a series of I/O and UI operations, which makes a poor match for testing)
c
I agree completely with your opinion about most apps!.. but I am pretty much TDD like I cannot stand to write code without tests..
I created a new project
just took the vanilla junit and got my tests running in a few mins but then
cannot figure out how to get at assertThat … does not offer to import
and the docs say you might have to add assertions but they don’t say how.. seriously if people are not writing enough tests it’s because there are too many logical people out there… they should hang a sign like the one in Dante on the testing page…
couldn’t get assertThat to work so I just did assertEquals.. one day I will make something from a template and it will work.. or wait I should say one day someone will…
k
Did you try manual import ? @codeslubber
c
yes
I got it to find assertThat
with manual import (which is like going back in time 2 decades)
but could not find the matchers
and there’s no mention of them in the docs
also
the docs show an example that I cannot see how it would compile
it has assertThat and is and no imports for either
k
Did u imported matchers? I found one topic on sof and one person was missing sth like org.hamcrest.CoreMatchers.*
c
ok so yeah got it to work now using assertThat and the core matchers
thanks @Karolo
I knew about the import thing not working but did not think hamcrest was there
because it was made from the vanilla template
(must be in the junit jars.. )
k
Hi, we managed to use spek in android project for unit tests but we were not contented with it due to its sharing state nature. So we created our own mini spek, which you can check here: https://github.com/elpassion/MiniSpek
👍 1
it’s still under development but for know it works for both android and unit tests, so I thought you might want to check it out