Can somebody tell me if there are some possibility to get the domain name in unittest and if no how generally this is solved;
Generally in UnitTest there are no such need because you can dispatch something like /edit.html and it works right;
For Selenium tests it is more difficult, of course we can hard code it in a variable, but I'm looking for solution to make it work on virtual host example.com/edit.html and on localhost: localhost/example/public/edit.html;
the domain name shouldn't have a bearing on your tests, and you need to mock these things up, be it the controller, view, etc. You don't run tests against the actual url, you test units of code against those portions of code within, for example, an action in the controller, or method in an action helper, etc.
check out the phpunit docs
Related
Our dev team provides us an Ansible package to work with. I noticed thy develop a custom stdout_callback and I'm trying to understand it.
I'm looking at the code of the class CallbackBase available here and I noticed the result variable but I can't find a description of it's content.
Is there a place I can find such information?
Next question, how does Ansible call such callback? CallbackBase contains several methods but I'd like to know where those methods are called.
Thanks for your feedbacks
Here's a little code I'm working on: http://pastebin.com/92Nzc6pG
I basically inject code into a running process, but the problem is, that CRT library is no longer valid, so I can't use strings for example. Is there any workarounds for that? Rest of my program requires creating/modifying strings as well, so I really need to get this sorted out.
I managed to get it working with passing a char pointer, like this: http://pastebin.com/T1qdjfRK
However using strings is still kind of a "must" for me, so any workarounds, ideas and whatsoever are welcome.
An easier way to do this would be to inject minimal code that just loads a DLL with proper imports and relocations. All of your imports are going to be satisfied by the loader once the DLL is loaded.
If you really must inject code and not a DLL for some reason, you'd have to make sure your code is compiled against the same CRT the process was compiled against. If it doesn't use CRT at all, you can use static CRT, or not use CRT at all. Windows has built-in string functions like lstrlen() and friends.
By far the simplest method is injecting an entire DLL and not just code. It will be a bit more complicated because it's two steps, but once you're fully loaded, you can do pretty much everything the same way you would have done it in your own process.
I am developing a Play! 2 application that generates some html/js widgets which will be embedded into 3rd-party websites. Their linking are dynamic thus I cannot have static test files.
How can I have test views(and routes to those views) that works only in test mode, so I can test with Selenium.
Basically I want to add testView1.scala.html, testView1.scala.html to test/views and have routes to that, but do not want that these work in production mode. What is a good approach to that?
i'm not sure if this is the best way, but here is how i would do it.
create the test route and route to a test controller
in the test controller, create a wrapped action and have all of your routes use this action
this wrapped action will test to see what mode play is in. if play isnt in test mode, forward to 404, otherwise, run the action
when i get home, ill add some code to support, but this is the general workflow i would use.
hope it helps.
Simples...(now with years to answer..). A bit similar to what #mbseid answered:
Rename your /conf/routes to /conf/prod.routes, and specify it in your /conf/application.conf:
play.http.router = prod.Routes
Create a test routes file, e.g. /conf/test.routes, that exposes the test only route and delegates the rest to the prod routes.
/test/only/something controllers.testonly.TestOnlySomethingController.someMethod()
-> / prod.Routes
Make sure your test only controllers are in a different package than other controllers.
When you start your test application override play.http.router, e.g.:
sbt run -Dplay.http.router=test.Routes
It is a useful pattern in microservices environments with integration tests to expose data not otherwise exposed.
Note, play.http.router used to be called application.router before v2.5+
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 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.