Comments (18)
I tried adding test-logback.xml (and logback-test.xml) with following content:
<configuration>
<root level="warn"/>
</configuration>
This doesn't seem to affect logging in any way, my log is still full of [Test worker] DEBUG io.mockk.impl...
lines.
How do I disable this?
from mockk.
For those curious:
Mockk uses Logback.
You need to add an logback-test.xml
or logback.xml
file in the resource
folder. Any other filename won't be recognised.
Then, in the xml, add something like this:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
Notes:
- Set
debug="false"
if you want to turn off logging completely. - Change the value to
level="info"
or"warn"
as you see fit. - You need to define an
<appender>
first, then use it in the<appender-ref>
. - You need to define the message pattern in
<pattern>
- Note the the
ref
can be any arbitrary value instead ofSTDOUT
.
Some links for reference:
- https://www.sentinelone.com/blog/getting-started-quickly-kotlin-logging/
- https://logback.qos.ch/manual/configuration.html
from mockk.
👍 +1 I am looking for the same option. What about?
val dependency = mockk<Dependency>(logging = false)
from mockk.
from mockk.
What do you propose? To disable info
and debug
logging? I don't think it is a good idea to remove logs. I would still prefer to see the option to enable/disable logs.
from mockk.
I propose to not have info
logs, so by default nothing is shown. There is just one info
message saying what is an answer. On the other hand you always can disable/show logging in logback.xml
(any other SLF4J framework) anyway. Doing it per mock is not an option because it would need to revisit each logging message and somehow link it to this flag.
from mockk.
It sounds like it is required to have SLF4J
on the classpath and then to include logback.xml
in the resources folder. Is it correct?
from mockk.
Yes, logback-test.xml
even better
from mockk.
I like the idea of not showing any logs by default. Frameworks like mockito also don't do this for example. I think that the logs are only useful when debugging the code so being able to easily turn this on/off would be a win I think.
from mockk.
The idea was to keep one top-level info message. It can help to see what has answered actually in your tests by mocking library. But I think this easily can be switched to DEBUG
from mockk.
Me personally not against the logging it was a good idea, but when you put additional logs in the source code to see sequence call with your tests it becomes a little bit noisy from the mock instances. I would still prefer to have logs, but with an option to disable them on demand. To use SLF4J
sounds like a solution, but it requires to add yet another lib just for the sake of disabling logs, which sounds like an overkill.
from mockk.
Version 1.7.10 released, please check if by default has no logging and close the ticket.
from mockk.
Awesome thanks so much, it works:) Really appreciate it!
from mockk.
@oleksiyp I'm confused by this. I don't want mockk logging and I use slf4j myself, but my logback is handled by dropwizard, so I don't have a logback.xml or test-logback.xml. Do I still need to create and configure a test-logback.xml to disable logging. It makes finding build failures in gradle output frustrating because there are all these mock DEBUG statements I have to wade through
from mockk.
Unfortunately, DEBUG is what MockK cannot live without. I usually request to turn on DEBUG logging to capture what is happening on the other side. It is pretty weird that it is turned on by default for tests with Dropwizard. So you need to configure test-logback.xml
to fix it.
I can think of a switch in MockK properties, but you will still need to create some file with settings, so that is almost the same as creation of test-logback.xml
from mockk.
from mockk.
After multiple hours I am still unable to turn off the DEBUG logs of mockk in my multiplatform project.
I enabled standard streams for my test logging:
testLogging {
showStandardStreams = true
}
I tried to add the logback.xml
or logback-test.xml
to shared/src/commonTest/resources/
.
I also tried to only enable standard streams for INFO log level only:
testLogging {
info {
showStandardStreams = true
}
}
But nothing seems to work. I want logging for all my INFO level logs but not the DEBUG level logs from mockk.
Has anyone found a solution, or could explain how to verify that the logback setup works?
from mockk.
I got it to work in my multiplatform project where I have tests in commonTest
.
The trick was to not add logback.xml
to shared/src/commonTest/resources/
but to shared/src/test/resources/
!
from mockk.
Related Issues (20)
- lateinit property has not been initialized on some ancestor classes HOT 2
- Using the result of callOriginal() inside coAnswers throws a fatal exception when the original contains a call to delay
- KotlinReflectionInternalError with HttpResponse.BodyHandler HOT 4
- Cannot create mock of interface, but of implementing class (method type parameters involved) HOT 2
- Error msg missing type information when no answers found for an overloaded method HOT 2
- kotlinx.datetime.Instant relaxed mock yields null java.time.Instant value
- NoSuchElementException in verify() HOT 3
- Bug: verify on anyConstructed<Mock>() throw an exception
- mockk-1.13.10 breaks tests that mock returning a value class HOT 2
- UInt properties cannot be mocked
- Poor performance with lateinit mockks
- Value class unboxing fails when mocked function and caller have the same name HOT 1
- mockkStatic/mockkObject not working HOT 2
- mockkObject not working in Maven
- Mockk deadlock during parallel tests
- Mocking doesn't work for a functional interface returning a value class
- Any.get() extension function is colliding with other classes extension function
- Can`t mock private property (Missing mocked calls inside every { ... } block: make sure the object inside the block is a mock) HOT 1
- Cannot mock kotlin object's get property that returns value class
- Mocking android.util.Pair throws exception HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockk.