I am trying to include a method in testng.xml file which is present in #Beforeclass annotation.Is there any way how can I achieve this?In google, all i can see is examples about inluding/excluding methods in #Test annotation ,but i am unable to find how we can include/exclude methods present in other annotations like before class,before method(Other then test annotation).
Well, you cannot control beforeClass, beforeMethod as they trigger automatically. If you want to control your method, you need to add #Test before it and then only you can ignore/include them.
If everytime, you want to execute them then you dont need to include them, they will get triggered always without mentioning them in testNG.xml
Related
I wanted to know whether you could debug a single method call
Say there's a method called howMany(char c,String str). I want to call it with 'c',"Hello world" and debug it without having to go through every previous code until I reach it
Thank you
You could try using Junit testing. This will allow you to call in a single method.
How to create unit tests easily in eclipse
I am able to Mole WebRequest.CreateUri so that I can replace the hostname of the request with another. However, I would like to Mole Dns.GetAddrInfo instead so that I can keep the hostname the same, but make it so that the hostname resolves to another IP address.
In this way, I do not have to edit my hosts file for example as this is a less flexible approach.
Any advice?
Thank you.
Edit
I've uploaded a sample Visual Studio 2010 sln to the problem here:
When opening the sln,
Click on the "Create Virtual Directory" button in the Service project properties' Web tab.
Rebuild the solution
Add the following entry to c:\windows\system32\drivers\etc\hosts:
127.0.0.1 www.productionserver.com
Run the TestMethod1 unit test in the Tests project.
The unit tests should succeed.
Remove the entry from the hosts file and re-run the unit test.
It should fail.
I have looked at the implementation of System.ServiceModel.ClientBase<TChannel> using a decompiler and noticed that it eventually calls System.Net.Dns.GetAddrInfo to resolve the hostname to an IP address.
I am hoping this sln is simple enough to update and send back (or just comment what needs to be done and\or changed) so I can simply see what is required to solve the problem.
Thank you.
Edit 2
It seems this is not currently possible with Moles.
The System.Net stack generally can not be moled, as much of he functionality are outside the control of the managed code.
Instead, create an interface and stub in your production code. Use the interface with dependency injection, to pass the stub to the target code. This stub simply calls the System.Net methods you wish to intercept, during testing.
Moles will automatically generate a Stub type, from the interface. Simply instantiate the stub type, detour the desired methods/properties/events of the stub, and then pass the Stub type to the method being tested.
Using stubs and dependency injection works wherever Mole types can not be created.
I mainly program Android, and one of the things I (and the rest of android programmers I'm sure) use with tenacity is android.util.Log. Every class I create has a
private static final String TAG = "ClassName";
tag that I write up as soon as I create the class, before I work on anything else. So, since I always create the tag I figured it would just save me on time (albeit a small amount) to just have it as part of the template for an empty class. My problem is, I don't know how or where to create code templates. Can anyone inform me on how to manage and create them?
What you're referring to are called "code templates" in Eclipse.
Go to Eclipse Preferences, search for "templates", you'll find them under Java -> Code Style -> Code Templates.
I would like to be able to run a set of unit tests by linking to them in my application (e.g. I want to be able to click on a link and have it run a set of jUnit tests). The problem is that GWT and jUnit don't seem to be designed for this capability -- only at build time can you run the tests it seems.
I would like to be able to include my test code in my application and, from onModuleLoad for example, run a set of tests.
I tried to just instantiate a test object:
StockWatcherTest tester = new StockWatcherTest();
tester.testSimple();
but I get:
No source code is available for type com.google.StockWatcher.client.StockWatcherTest;
even though I include the module specifically.
Would anyone know a way to do this? I just want to be able to display the test results within the browser.
If you are trying to test UI elements in GWT using JUnit, unfortunately you may not do so. JUnit testing is limited to RPC and non-UI client-side testing. See this thread for a great discussion on what you can and cannot do with GWT jUnit testing.
If you are not trying to test UI elements, but are instead trying to inject your RPC code or client-side logic with test values (hence why you want to be able to click on a link and run a set of JUnit tests), then you should follow the following guide from testearly.com: Testing GWT with JUnit. In short, you should make sure that the method you are testing does not include any UI elements and if the method you are testing is asynchronous in nature, you must add a timer.
In 2.0, HTMLUnit was added. You may wish to use this instead of firing up a browser each time you wish to test.
I'm working on a GWT project and I find it very tedious to have to add a function to my servlet, then copy and paste the function signature into my Service interface, then copy and paste it into my ServiceAsync interface and change the return parameter to be a callback. Is there a tool or a setting where I can just add public methods to my class and they can get copied into the other interfaces? Even if its not automatic it would be nice to be able to select specific methods and have them copied automatically.
I'm using eclipse and ideally it would update my interface each time I save implementation since thats when it checks my code and complains that my changes break the interface.
If you add the method to your *Service interface, then Eclipse can auto-generate the method ("Add unimplemented methods...") in your *ServiceImpl servlet, which you can then just fill in. Also, if you've got the Google Eclipse plugin installed, it will underline the new method in your *Service interface and complain that it's not in the *ServiceAsync. It might have a CTRL + 1 option to generate it in that interface as well.
You don't really need a tool. Just factor out the many RPC methods by just one method that takes a Request/Response. all you need to do is create subclasses of Request/Response and you don't need to think about adding new methods in the 2 interfaces.
You can use Google Guice on the server side to map the incomming request to a class handling the call... or you could use a visitor approach to forward the incoming request to the code handling the request (without resorting on a big instanceof construct).
Instantiations WindowBuilder GWT Designer does exactly what you are looking for.
The RemoteService Wizard will create all three files at the same time as well as keep them in sync as you make changes.
http://www.instantiations.com/windowbuilder/gwtdesigner/index.html
FWIW - I am only a user/purchaser of this product. I am not employed or in any other way related to Instantiations.