Hi I'm looking for way to improve my test ```@Tes...
# konsist
s
Hi I'm looking for way to improve my test
Copy code
@Test
    fun `ViewModel class should not have 'Context' as parameter`() {
        moduleScope
            .classes()
            .withAllParentsOf(ViewModel::class)
            .constructors
            .assert {
                it.hasParameterNamed("context")
            }
    }
My test is to ViewModel should not directly receive context as parameter for this I have written above test which work but devs can write any name like context, appContext, mContext. I wanted to know how can I check parameter Type i.e does constructor has any parameter of Context type
i
Try this
Copy code
.assert {
    it.parameters.none { parameter -> 
        parameter.representsTypeOf<Context>() 
     }
}
1
s
Thanks