Your data. Anywhere you go.

New Relic for iOS or Android


Download on the App Store    Android App on Google play


New Relic Insights App for iOS


Download on the App Store


Learn more

Close icon

How to run the units test of the "metrics publish java" and add my tests too

plugins

#1

Hey guys,

I am refactoring a script plugin that was wrote in java, and I am not fluent in java I really prefer cpp or python, but I want to run and add unit tests, and looking to the build.xml file there is no mention to the tests or how to run then. Can you guys give me a hand?


#2

Hi, @eduardo.augusto: That plugin does not look like it is officially supported by New Relic. I recommend that you contact its author directly.


#3

I know that, but its not about the unit test of the plugin, it is about the unit tests of the Java Metric Publisher. There is no way to run or build the code under the folder test?
As i said, looking for the build.xml there is no mention of the build of the tests.

Am I on my own lucky?

I found it how to build it ,

Thanks for nothing.


#4

Hey @eduardo.augusto - Thanks for confirming you found out how to build those tests and build.xml - and I’m sorry we misinterpreted your question in the beginning. Let is know if there’s anything else we could help with :slight_smile:


#5

Now I am trying to ran these tests, but it seems they are broken. This is right?

test:
[junit] Running com.newrelic.metrics.publish.AgentTest
[junit] Testsuite: com.newrelic.metrics.publish.AgentTest
[junit] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0,016 sec
[junit] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0,016 sec
[junit]
[junit] Testcase: testOnePollCycle(com.newrelic.metrics.publish.AgentTest): Caused an ERROR
[junit] ch/qos/logback/core/Appender
[junit] java.lang.NoClassDefFoundError: ch/qos/logback/core/Appender
[junit] at com.newrelic.metrics.publish.Agent.(Agent.java:16)
[junit] at com.newrelic.metrics.publish.AgentTest.testOnePollCycle(AgentTest.java:25)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.Appender
[junit] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[junit] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[junit] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[junit]
[junit]
[junit] Testcase: testOnePollCycleWithMultipleComponents(com.newrelic.metrics.publish.AgentTest): Caused an ERROR
[junit] ch/qos/logback/core/Appender
[junit] java.lang.NoClassDefFoundError: ch/qos/logback/core/Appender
[junit] at com.newrelic.metrics.publish.binding.Context.(Context.java:26)
[junit] at com.newrelic.metrics.publish.AgentTest.testOnePollCycleWithMultipleComponents(AgentTest.java:76)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[junit] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[junit] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[junit] Caused by: java.lang.ClassNotFoundException: ch.qos.logback.core.Appender
[junit] at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
[junit] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
[junit] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
[junit]
[junit]
BUILD FAILED
/home/eduardo/ScriptAgentNewRelicPlugin/build.xml:77: Test com.newrelic.metrics.publish.AgentTest failed


#6

I updated my build file to append the right classpath during the tests and now it is working, it would be nice to you guys update your build file too, its important to the quality of the development of plugins the unit test…

eduardo@cred-JCJ7VW2:NewRelicScriptAgentPlugin jobs 1 (master)
-> ant test
Buildfile: /home/eduardo/NewRelicScriptAgentPlugin/build.xml
clean:
[echo] Cleaning project…
[delete] Deleting directory /home/eduardo/NewRelicScriptAgentPlugin/build
[echo] Done.
init:
[echo] Creating directory: build
[mkdir] Created dir: /home/eduardo/NewRelicScriptAgentPlugin/build
[mkdir] Created dir: /home/eduardo/NewRelicScriptAgentPlugin/build/test
compile:
[echo] Building project…
[javac] Compiling 22 source files to /home/eduardo/NewRelicScriptAgentPlugin/build
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Creating empty /home/eduardo/NewRelicScriptAgentPlugin/build/com/scriptagent/package-info.class
[echo] Done.
test-compile:
[javac] Compiling 35 source files to /home/eduardo/NewRelicScriptAgentPlugin/build/test
[javac] /home/eduardo/NewRelicScriptAgentPlugin/test/src/com/newrelic/metrics/publish/util/LoggerTest.java:122: warning: non-varargs call of varargs method with inexact argument type for last parameter;
[javac] Logger.buildMessage(null);
[javac] ^
[javac] cast to Object for a varargs call
[javac] cast to Object[] for a non-varargs call and to suppress this warning
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] 1 warning
[javac] Creating empty /home/eduardo/NewRelicScriptAgentPlugin/build/test/com/scriptagent/package-info.class
[echo] Done.
test:
[junit] Running com.newrelic.metrics.publish.AgentTest
[junit] Testsuite: com.newrelic.metrics.publish.AgentTest
[junit] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,101 sec
[junit] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,101 sec
[junit]
[junit] Running com.newrelic.metrics.publish.binding.AgentDataTest
[junit] Testsuite: com.newrelic.metrics.publish.binding.AgentDataTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,009 sec
[junit] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,009 sec
[junit]
[junit] Running com.newrelic.metrics.publish.binding.ComponentDataTest
[junit] Testsuite: com.newrelic.metrics.publish.binding.ComponentDataTest
[junit] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,077 sec
[junit] Tests run: 5, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0,077 sec
[junit]
[junit] Running com.newrelic.metrics.publish.binding.ContextTest
[junit] Testsuite: com.newrelic.metrics.publish.binding.ContextTest
[junit] Tests run: 11, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0,126 sec
[junit] Tests run: 11, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0,126 sec