javassist works on simple java app but does not work within web app(spring) - javassist

I have simple java app with part of scala code and there are java agent which catch all methods i need and inject my code into them.
Problem appear when i try do the same action within web app(spring), but my agent only catch methods and inject code and when that methods is called my injecded code not run.
What is may be wrong in this case?

Desicion is to fix bugs in javaagent code, he is not printing stacktraces

Related

Robot Framework - capture screenshot when any keyword fails (not only selenium keywords)

I'm making automated tests cases with mix of selenium and builtin keywords in Robot Framework.
I have made the:
Register Keyword To Run On Failure Screenshot On Failure
which overwrites the default behavior to create selenium-screenshot-index.png (I needed other names). Everything works fine if the keyword failing is part of the selenium library. If not (let's say custom or builtin one) the screenshot is not taken.
Is there a way, to register the keyword to run on any failure in any keyword?
Well, depending on your actual goal solution could be quite simple or require a little bit of python programming.
Simple solution. I would say that taking one screenshot in test teardown if test case failed is enough in most of the cases.
Writing custom listener interface that would grab instance of library (Selenium, OS) and depending on keyword status would take action.

Print codepath for starting method and data

Is there a tool/method to list all function calls(codepath) for a starting point consisting of a specific method and some data(both global and function argument)?
This is a Visual Studio MFC console C++ project.
I thought of using AOP to tackle this, but it would be my first try at AOP, and would prefer a proven solution.
Additional problem for profiling is that the app has an infinite while listener and is multithreaded + "inter-process communication" (so profiler would have to pickup on other process response, and filter calls within while loop).
Is static code analysis a viable solution for this, or should i continue looking for profiling and AOP to solve this?

Why do I get an Invalid Operation Exception (non STA thread?) running this MSpec test on TeamCity?

As part of the migration of my app to .NET 4, I'm struggling to get some of the WPF unit tests working again with TeamCity.
On all the tests that are somehow using a WPF control (a ListItem for example), I get an exception I didn't get before:
System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
I understand what it means, and after checking, it turns out that my thread is indeed MTA, not STA.
My problem is that I have no idea on how to fix this, and where this problem could be coming from...
Is it a setting on TeamCity? MSpec?
Again, it worked before I switched to .NET 4.
I tried many different solutions, but nothing worked.
I'm also a bit puzzled by the fact that no-one reported this before (with my specific stack of TeamCity + MSpec + WPF test), which might mean I'm doing something very wrong somewhere.
If you have a clue, please let me know!
Full exception:
System.InvalidOperationException: The calling thread must be STA, because many UI components require this.
at System.Windows.Input.InputManager..ctor()
at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
at System.Windows.Input.KeyboardNavigation..ctor()
at System.Windows.FrameworkElement.EnsureFrameworkServices()
at System.Windows.FrameworkElement..ctor()
at System.Windows.Controls.Control..ctor()
at MyCompany.Dashboard.Client.Plugins.Common.Controls.Grids.CashflowGrid.ViewModel.ConfigureViewModel.CreateItem(String name) in d:\Program Files\JetBrains\BuildAgent2\work\6dd9af6ae2f9bbb9\Code\Src\MyCompany\Dashboard\Client\Plugins\Common\Controls\Grids\CashflowGrid\ViewModel\ConfigureViewModel.cs:line 171
at MyCompany.Dashboard.Client.Plugins.Common.Controls.Grids.CashflowGrid.ViewModel.ConfigureViewModel.Initialise(Type type, IList`1 currentSelection, Action`1 selectionChangedCallback) in d:\Program Files\JetBrains\BuildAgent2\work\6dd9af6ae2f9bbb9\Code\Src\MyCompany\Dashboard\Client\Plugins\Common\Controls\Grids\CashflowGrid\ViewModel\ConfigureViewModel.cs:line 37
at UnitTests.Plugins.Common.Controls.Grids.CashflowGrid.ViewModel.when_some_items_are_selected_on_the_chosen_list.<.ctor>b__1() in d:\Program Files\JetBrains\BuildAgent2\work\6dd9af6ae2f9bbb9\Code\Src\UnitTests.Plugins.Common\Controls\Grids\CashflowGrid\ViewModel\ConfigureViewModelTests.cs:line 82
For this exception, the code is simply trying to instantiate a ListBoxItem, nothing fancy, but doing that on a MTA thread breaks it.
What I tried:
Setting the current thread to STA
Thread.CurrentThread.SetApartmentState(ApartmentState.STA)
It of course doesn't work because it's only possible before the thread starts
Run the code in a separate thread that was initialised as STA:
very complex since, due to the nature of MSpec, different methods are called at different time so you can't run EVERYTHING under the same thread. More precisely, you can't run the "Establish context" on the same thread as the "Because of" statement.
Use the STAThread attribute... yes but where? never worked anywhere I
tried
Example of a failing test:
public class StaTestExample
{
Establish context = () => _control = new ListBox();
It should_not_be_null = () => _control.ShouldNotBeNull();
protected static Control _control;
}
It now works.
But the problem is we just can't explain it. And it still fails on a different build server, but we don't care about this one.
In case someone gets that problem, here what we did:
Disabling test coverage
Disabling the MSPec task: the build goes green
Re-enabling coverage and MSpec: it works...
The odd thing is that exact process was applied on a different build server (an old one we don't use anymore), and it still fails.
There's nothing else we could think of that changed.
So it's a bit of a mystery... I hope it won't come back to bite us!

Replicate class with main method as in Java IDE within Objective-C and Xcode 4

I have a simple question. Coming from a java background and having worked extensively with eclipse, netbeans or any other java IDE, is quite nice to have the possibility to add a main method to a class and execute it within the IDE, with just a click, and see the output.
I was looking for the same possibility within xcode4/objective-c but I couldn't find a way. From time to time, I like testing small piece of software, without compiling and running the whole project.
As I am still "thinking" in Java, could you suggest the proper way to achieve this with xcode4 from an "objective-c developer point of view" ?
thanks
There's not really a lightweight way to do this, but you have two options that I can think of depending on whether you want to keep the harness code you've written.
If you do, then you'd need to make a new target in your project for each class you drive with a harness, and have that target build just the class you are driving and a simple file with just the main code to drive that class.
If you don't, then you could make a target with a main, and each time you want to drive a different class, change which files are built, change the code in main, and rebuild.
This is assuming that you want to avoid both running and compiling the rest of your code. If you don't mind compiling everything, you could have one test-harness target that builds all of your classes, and either change main on the fly, or use #ifdefs or a runtime argument to decide which helper code to run.

GWT testing without GWTTestCase and the DOM

Can I test my client side GWT code without GWTTestCase? I've heard somewhere (I think it was one of the Google IO 2009 conferences) that they were successfully testing their code with a fake DOM, in the JVM and not in Javascript with the DOM. That would be brilliant. The point of this would be to gain speed (order of magnitude). Does anybody have any idea about how to do this? My first question on stack overflow, hope I'm doing this right.
Thanks.
Eugen.
You should check out the Google I/O session by Ray Ryan.
Basically, you can use the Model/View/Presenter pattern and abstract away all the DOM-accessing code to the 'View' portion. By doing this, you can create a mock view and test the model/presenter using standard junit tests, running via the jvm, without the need for a browser or a DOM
Not quite what you're looking for, but you should use the Model-View-Presenter pattern. Any code that requires the DOM should go in your View classes, and should be as dumb as possible. Complex logic goes in your Presenter classes. You can then test your presenter classes without needing a GWTTestCase.
E.g, a view might have a method like:
void setResponseText(String text);
Your presenter test case can then look something like:
void testSayHi() {
expect(mockView.setResponseText("hi there"));
replayMocks();
presenter.sayHi();
verifyMocks();
}