I have a test suite for my application, and some of the time when I'm building my project one the tests raises this error, and sometimes, if I run all the tests again, the error doesn't appear. and if I run this specific test seperatly it always passes.
this is the error:
com.google.common.util.concurrent.UncheckedExecutionException: java.lang.IllegalStateException: Interrupted while loading cache item
at functional.TestFile.init(TestFile.java:32)
Caused by: java.lang.IllegalStateException: Interrupted while loading cache item
at functional.TestFile.init(TestFile.java:32)
Caused by: java.lang.InterruptedException
at functional.TestFile.init(TestFile.java:32)
and this is the line which raises the error:
private File testDirectory;
private Injector injector;
#BeforeClass
public void init() throws Exception {
testDirectory = Files.createTempDirectory(null).toFile();
injector = Guice.createInjector(Modules.override(new ProductionModule(new ApplicationSettings().getProperties())).with(new TestModule(testDirectory)));
}
the injector line is line num 32.
anyone knows why it is not stable and why sometime ot pass and sometime not?
Related
When running this test:
const file = "exp.txt";
Deno.test("handle rejected promise", async (t) => {
try {
await Deno.stat(file);
} catch (e) {
if (e instanceof Deno.errors.NotFound) {
await Deno.writeTextFile(file, "some text");
} else {
throw e;
}
} finally {
await Deno.remove(file);
}
});
When running it like so:
deno test --allow-read --allow-write exp.test.ts
the test succeeds.
However, when running it like so (adding the trace-ops option):
deno test --allow-read --allow-write --trace-ops exp.test.ts
it fails with:
./exp.test.ts (uncaught error)
error: (in promise) NotFound: The system cannot find the file specified. (os error 2), stat 'exp.txt'
This error was not caught from a test and caused the test runner to fail on the referenced module.
It most likely originated from a dangling promise, event/timeout handler or top-level code.
I have more involved code doing essentially the above failing even without --trace-ops. It appears to be more of a race condition or some timeout.
This is deno 1.28.3 and I've tried with several 1.2x versions with flaky results. However, it never bit me before running 1.28.3.
Note this way of checking a file's existence is suggested by the deno docs e.g. here
This turned out to be a bug and after submitting an issue it was fixed and should be included in a new release of Deno (1.28.3+).
This is my Unit Test:
[TestCategory("Repo")]
[TestMethod]
[ExpectedException(typeof(System.ServiceModel.FaultException))]
public void RepoUnitTest_ExpectError()
{
var repo = new CreateClientRepository(ClientServiceWrapper);
IClientObject input = new ClientObject
{
ClientId = 0,
ClientName = null
};
repo.CreateClient(input);
}
I am providing invalid input to my client repository which in turn calls a third party client service, and I expect the client service to throw an error. And, client service throws an exception too, but not the way I expect it. I expect it "System.ServiceModel.FaultException", but it give me this:
Test method RepoUnitTest_ExpectError threw exception
System.ServiceModel.FaultException`1[[System.ServiceModel.ExceptionDetail, System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]],
but exception System.ServiceModel.FaultException was expected.
Not sure what do I put in "ExpectedException" so this Unit Test passes with correctly expected exception.
Guess I should have waited few more minutes before posting this question, but I am glad did, now I can share the knowledge with whoever stumbles upon similar issue.
The expected exception should be written this way (for this particular case):
[ExpectedException(typeof(System.ServiceModel.FaultException<
System.ServiceModel.ExceptionDetail>))]
Using Camel-core v2.14.1 and camel-testng v2.14.1
Attempting to Unit Test a basic route.
The RouteBuilder class is named as FileToJmsRB and the Route is configured this way
#Override
public void configure() {
from("file:C:\\camel_folder\\orders")
.when(fileToJmsConditions.camelFileNameEndingWithXml(this))
.to("file:C:\\camel_folder\\recieved")
}
fileToJmsConditions is a variable that I am failing to inject as Spring Bean.
My Test class extends CamelTestSupport and it overrides createRouteBuilder() as follows
#Override
protected RouteBuilder createRouteBuilder() throws Exception{
return new FileToJmsRB();
}
and I configure a method as test.
#Test
public void testTextFileMove() throws Exception{
template.sendBodyAndHeader("file:C:\\camel_folder\\orders"
, "Hello World"
, Exchange.FILE_NAME
, "hello.txt");
Thread.sleep(10000);
File target = new File("C:\\camel_folder\\recieved\\hello.txt");
assertTrue(target.exists(), "File Not Moved");
}
On running
maven install
on the project, I expect a Null Pointer Exception with a StackTrace in Console.
However, observation no hint of type of Exception Thrown and there is not stacktrace printed. It just says that the test failed but does not prints the type of exception or stacktrace.
Tests run: 2, Failures: 1, Errors: 0, Skipped: 1
However, if I wrap my configure method in FileToJmsRB class with
try... Catch...
Only then do I see the NullPointerException thrown and Stack Trace printed.
Is there no other, more elegant way of handling this more elegantly? Because this way I must do try...catch... in every Route Builder class?
I try to automate some unit tests with our TFS build process and some tests results have this error: "The agent process was stopped while the test was running."
All of them have the "ExpectedException" attribute. For example:
[ExpectedException(typeof(SuEnlaceModelException))]
public void SuEnlaceModelParser_ParseDatesError_MonthIsNotANumber()
{
var testingDatesFakeModel = new TestingDatesFakeModel();
SuEnlaceModelParser.ParseLine(testingDatesFakeModel, "x", "2014no01");
Assert.Fail("Exception must be thrown before reaching this Assert");
}
When I run these tests from the Test Explorer, the results are "Test passed". But when they are executed from the build, they ends up with the previous error.
Why is this happening? How can I fix it?
Thanks.
I found what caused the error!
I had one try-catch with next sentence in the catch region:
Debugger.Break();
I delete this line and now all test results are OK.
I am using WPToolkitTestFx Unit test framework for the Windows Phone 8 application. I am getting below error when I am executing Assert.Fail() or Assert.IsFalse(true).
A first chance exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTesting.Phone.DLL
Any solution to the above error.
Here the source code
[TestMethod]
[Asynchronous]
[Description("Test2: Sample asynchronous test")]
public void Test2()
{
// this test executes asynchronously
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
// ... and then fails
Assert.IsFalse(true);
EnqueueTestComplete();
});
}
Thanks,
Ragu
I can see something similar when following the sample code from http://blogs.windows.com/windows_phone/b/wpdev/archive/2012/11/20/windows-phone-toolkit-overview.aspx.
It is normal for the exception to occur, and see:
A first chance exception of type 'Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException' occurred in Microsoft.VisualStudio.QualityTools.UnitTesting.Phone.DLL
Also if the debugger is attached to your device/emulator, the debugger will break so you can find out where the test failure was.
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
Debugger.Break(); // <- !!! application will stop in debugger here !!!
}
}
However if you continue the project (press F5), or are not running under the debugger, you will see that the application continues to run and doesn't get exited.
That allows you to see your test results.
Question, is it a normal part of your test to fail the assertion? if so, you need to instruct the framework to expect such exception to happen
[TestMethod, Asynchronous]
[Description("Test2: Sample asynchronous test")]
[ExpectedException(typeof(AssertFailedException))]
public void Test2()
{
// this test executes asynchronously
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
// ... and then fails
Assert.IsFalse(true);
//TestComplete();
});
}
Also I notice that you are marking the method as Asynchronous, but you are not using the asynchronous invocation methods of EnqueueDelay(TimeSpan), EnqueueCallback(), EnqueueTestComplete() are the ones that make the method function asynchronous.