Nullpointer Exception on Jenkins - unit-testing

I am getting an error on my Jenkins build, which I checked in the logs is using the command
[![enter image description here][1]][1]
It shows Tests run: 211, Failures: 1
But when I run the same maven command under my project, all tests pass, and it shows
Tests run: 211 Failures: 0
that's weird, and I have no idea what could be going on and how to reproduce the issue
. The same branch that I am working on locally is deployed through Jenkins.
On the jenkins the test function that is failing is this:
public void test_tbe_event_cancel() throws I0Exception {
System.out.println("Inside test_tbe_event_cancel");
givenTheTbeCancelFixMessage(testTBECancelFix()).processTBEHistoricCancel(historicMessageEventHandler, positionEvent -> {
(positionEvent.getSideMarkPosition(), 7500.0);
(positionEvent.getCurrentPosition(), 7500.0);
(positionEvent.getBuyQuantity(), 7500.0);
1)
.andAssertBookPosition(bookPosition -> {
(bookPosition.getSideMarkPosition(), 7500.0);
(bookPosition.getCurrentPosition(), 7500.0);
(bookPosition.getBuyQuantity(), 7500.0);
(bookPosition.getSellQuantity(), 0.0);
(bookPosition.getSellValue(), 0.0);
1);
System.out.println("exiting test_tbe_event_cancel");
}
and the exception is :
NullPointerExceptionm which is happening on the above function: test_tbe_event_cancel
at line .andAssertBookPosition(bookPosition -> {
Any ideas on how do I debug this issue, or reproduce it on my local system.
I initially tried with mvn clean install command which worked and then tried the
longer maven command used on Jenkins box that too works on local box surprisingly, I was
expecting that the error could be reproduced if I use the exact same command, but it
didn't happen
[1]: https://i.stack.imgur.com/nF02b.png

Related

Flutter build fails due to Amplify_core

I recently upgraded my flutter application to Android V2, and also made my code null safe.
Now when I try to run my code I get the below build error:
e: C:\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-
0.4.0\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (26, 1):
Class 'AtomicResult' is not abstract and does not implement abstract member public abstract
fun error(p0: String, p1: String?, p2: Any?): Unit defined in
io.flutter.plugin.common.MethodChannel.Result
e: C:\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-
0.4.0\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (54, 5):
'error' overrides nothing
e: C:\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-
0.4.0\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (66, 26):
Type mismatch: inferred type is String? but String was expected
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':amplify_core:compileDebugKotlin'.
> Compilation error. See log for more details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get
more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 15s
Exception: Gradle task assembleDebug failed with exit code 1
Things I tried that did not work:
Clearing build and cache and restarting
Deleted the amplify_core-0.4.0 from the pub.dartlang.org folder and tried again
Initialized Amplify again and pulled the environment from the Launch Studio again
Any help would be greatly appreciated!
Thanks
I was able to solve this issue by changing my channel from Master to Stable.
In the next release of Amplify staying on the Master channel won't present this issue.
run this command -->>
dart pub upgrade --major-versions

How to Add Better Logging to Debug when a Previously Working VSTS Build Times out When Executing Unit Tests step

I have a VSTS build with Unit tests that was working previously in VSTS build. This week, it stopped working due to timing out.
The failure occurs due to timing out after 60 minutes.
Here's what we know:
The test library only contains 1 test. We run the test by pointing to the test assembly in the Unit Tests configuration of VSTS.
The test still works locally (runs in <1 second).
Even if I remove the actual test and replace it with a single trivial test that just checks Assert.IsTrue(true), the test still time out. So we conclude that it's something about the test configuration, rather than the test itself, causing the issue.
I tried adding additional Debug logging to the test, but it appears that the test execution never actually starts.
No trx log file appears to be generated. It doesn't appear to actually attempt to run the test at all.
We have tried this in a VSTS hosted VM and on our own VM with the same result.
We tried adding a new test step to the build and pointing that the the test DLL with no other modifications to the defaults, and it still gets stuck.
We pointed the original test step to a different test DLL, and the tests pass! So there is something related to this particular lib that is different (but again, even if I remove all the tests it still gets stuck).
Does anyone have alternate suggestions for other things to try to narrow down what could be causing this (e.g., trace logging in VSTS)? The log file below shows some of the specifics of our unit test configuration, but please let me know if other details would be helpful.
The failure log looks like this:
> ============================================================================== 2018-07-18T20:14:25.1963123Z Run the tests locally using
> vstest.console.exe 2018-07-18T20:14:25.1964566Z
> ======================================================== 2018-07-18T20:14:25.1965645Z Test selector : Test assemblies
> 2018-07-18T20:14:25.1966925Z Test assemblies : **\<PathToTestLib>.dll
> 2018-07-18T20:14:25.1968187Z Test filter criteria : null
> 2018-07-18T20:14:25.1968810Z Search folder : C:\vsts-agent\_work\4\s
> 2018-07-18T20:14:25.1969311Z Run settings file :
> C:\vsts-agent\_work\4\s 2018-07-18T20:14:25.1970327Z Run in parallel :
> false 2018-07-18T20:14:25.1970792Z Run in isolation : false
> 2018-07-18T20:14:25.1972913Z Path to custom adapters : null
> 2018-07-18T20:14:25.1973153Z Other console options : null
> 2018-07-18T20:14:25.1973381Z Code coverage enabled : false
> 2018-07-18T20:14:25.1974004Z Rerun failed tests: false
> 2018-07-18T20:14:25.1974423Z VisualStudio version selected for test
> execution : latest 2018-07-18T20:14:25.3811086Z
> ======================================================== 2018-07-18T20:14:30.6014691Z [command]"C:\Program Files
> (x86)\Microsoft Visual
> Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"
> #C:\vsts-agent\_work\_temp\2aa40f41-8ac7-11e8-b190-a1cdff2b8b30.txt
> 2018-07-18T20:14:30.8198002Z Microsoft (R) Test Execution Command Line
> Tool Version 15.7.2 2018-07-18T20:14:30.8206458Z Copyright (c)
> Microsoft Corporation. All rights reserved.
> 2018-07-18T20:14:30.8206862Z 2018-07-18T20:14:30.8227447Z
> vstest.console.exe 2018-07-18T20:14:30.8228082Z
> "C:\vsts-agent\_work\4\s\partners\exooutlook\OutlookAnalysisSolution.Test\bin\Debug\OutlookAnalysisSolution.Test.dll"
> 2018-07-18T20:14:30.8228647Z /logger:"trx"
> 2018-07-18T20:14:31.0672644Z Starting test execution, please wait...
> 2018-07-18T21:14:05.8979923Z ##[error]The operation was canceled.
> 2018-07-18T21:14:05.9027909Z ##[section]Finishing: Unit Tests
We found the source of the hang. It was in a test class method marked with the "AssemblyInitialize" attribute.
[TestClass]
public class TestClassInitializer
{
[AssemblyInitialize]
public static void AssemblyInit(TestContext context)
{
LocalResourceDeployment.CopyResources();
}
}
There was a bug in CopyResources() that did not manifest locally but caused a powershell window in VSTS to wait for console input.
We have improved the trace logging in this initialization method so that if it fails again in the future we'll at least have a pointer to where the test got stuck. E.g.:
Trace.WriteLine("Starting test assembly initializtion.");

teamcity test never fails

I am implementing a Powershell build script for teamcity to test some functionality, but cannot figure out out to report an error.
I am trying to follow this description:
https://confluence.jetbrains.com/display/TCD8/Build+Script+Interaction+with+TeamCity#BuildScriptInteractionwithTeamCity-ReportingTests
However, although the script actually results in some tests being registered, it refuses to report errors. I am now back to the basic example from the . I have the following Powershell build step (error output: error, script: source):
Write-Host("##teamcity[testStarted name='className.testName']")
Write-Host("##teamcity[testStdErr name='className.testName' out='error text']")
Write-Host("##teamcity[testFinished name='className.testName']")
Resulting build log (verbose):
[13:27:12]Step 1/5: Output to build log (Powershell)
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:firstStepPreparation' value='156.0']
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='0.0']
[13:27:13][Step 1/5] Starting: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -Command - < D:\JetBrains\buildagent\temp\buildTmp\powershell6640337654487221076.ps1
[13:27:13][Step 1/5] in directory: D:\JetBrains\buildagent\work\7e3fac8e390ca38d
[13:27:13][Step 1/5] className.testName
[13:27:13][className.testName] [Test Error Output] error text
[13:27:13][Step 1/5] Process exited with code 0
[13:27:13][Step 1/5] ##teamcity[buildStatisticValue key='buildStageDuration:buildStepRUNNER_18' value='536.0']
I.e. the test is registered in teamcity as executed bit it succeeds! I would expect the test to fail, due to the 'testStdErr' output! What it the correct way to make it fail?
Thanks,
Kim
You should use the testFailed directive which is listed on the page you linked:
##teamcity[testFailed name='MyTest.test1' message='failure message' details='message and stack trace']
Or change the build failure condition settings under 'Build Failure Conditions' to fail the build if you write to stderr (edit: this is my understand of the docs anyway):
Fail build if:
[ ] an error message is logged by build runner

Problem running tests under Netbeans

I am running some Junit tests and Netbeans behaves strangely giving the report in "Output" window:
Testcase: warning(junit.framework.TestSuite$1): FAILED
No tests found in uk.ac.cam.ch.wwmm.chemicaltagger.ChemistryPOSTaggerTest
junit.framework.AssertionFailedError: No tests found in uk.ac.cam.ch.wwmm.chemicaltagger.ChemistryPOSTaggerTest
Test uk.ac.cam.ch.wwmm.chemicaltagger.ChemistryPOSTaggerTest FAILED (crashed)
test:
BUILD SUCCESSFUL (total time: 12 seconds)
The (5) tests are there. I have run mvn test which runs them but fails on OutOfMemoryError. Is this likely to be the cause of the Netbeans problem?
How did you created your test file? Manually, or using NB wizard? (Tools - Create JUnit test from Java file's popup menu)
If you are using JUnit 3, all test methods in your test file must start with "test", e.g.
public void testFoo() { //some testing here :) }
With JUnit 4, a '#Test' annotation is required, e.g.
#Test
public void myOwnTestFoo() { //...}
Otherwise JUnit does not recognize the test and throws AssertionFailedError error.

MSBuild: build results shows 'no code coverage' while importing test-result does

I have a strange problem,
my MSBuild runs tests, code-coverage and publishing fine (part of the build.txt shown):
Results Top Level Tests
------- ---------------
Passed BuildTestProject.UnitTest1.TestMethod1
Passed BuildTestProject.UnitTest1.TestMethod2
2/2 test(s) Passed
...
Results file: W:\BuildWorkspace\XXX\Test Release\TestResults\XXX_XXX 2009-08-20 11_47_09_Any CPU_Release.trx
Run Configuration: Local Test Run
Waiting to publish...
Publishing results of test run XXX#XXX 2009-08-20 11:47:09_Any CPU_Release to http://XXX:8080/Build/v1.0/PublishTestResultsBuildService2.asmx...
....Publish completed successfully.
When I import these testresults on my local machine i get to see the code coverage-data as expected. But the code-coverage details are not shown in the details of the build that Visual Studio shows when you expand the 'results details'.
Any tips?
Finally found the solution today, found out that my TeamFoundationServer itself had problems with publishing the results to my buildAgent. I read somewhere (after searching for CoverAn.exe) that it is installed as a service, then i checked the credentials for the service 'Code Coverage Analysis Service'.
These were running under TFSMachine\NETWORK instead of our service-account for the TeamFoundationServer. Changed this, reran a build with tests in it and it now publishes the results.
W00t!
Check that the .testrunconfig used by the server has coverage enabled. It may be different than your local .testrunconfig.