I'm using PHPunit to test our Zend Framework project and it works allright but i'm not getting coverage om my action methods in my controllers.
Although I get coverage in number off lines of code but I want to have coverage on the functions/methods.
I see a lot of examples on the internet where they just do it like this:
class IndexTest extends Zend_Test_PHPUnit_ControllerTestCase
{
public function testIndexAction() {
$this->dispatch('/');
$this->assertController('index');
$this->assertAction('index');
$this->assertXpath("//form[#action = '/index']");
}
}
Which should work even if I look to this example from Jon:
http://www.zendcasts.com/unit-testing-with-the-zend-framework-with-zend_test-and-phpunit/2009/06/
http://code.google.com/p/zendcasts/source/browse/#svn/trunk/zc25-unit-testing
I'm doing it almost the exact way but it's not giving me any percentage of code coverage in functions, except for the init() function but I think that one is automaticly ignored by Zend Controller testcase.
I'm I doing something stupid or doesn't PHPUnit reconize it's calling this action? Using PHPUnit 3.5.14 and Zend Framework 1.11.x
To get code coverage for a specific function from PHPunit you need to make sure every line of your function is called by your tests, so that every possible situation is taken care of and tested.
Related
I am trying to find a way to create custom suites of NUnit tests to target our wide variety of environments. The closest thing I found was this http://nunit.org/docs/2.5.6/suite.html which is exactly what I am looking for. Tying to implement this though, the [Suite] annotation doesnt even seem to exist.. Was this taken away? Is there a better solution now?
The SuiteAttribute was eliminated in NUnit 3. It never got a lot of use as most people simply organize their tests by namespace, which provides the same grouping of tests that the SuiteAttribute used to do.
FUN FACT: "Automatic namespace suites" were once a new cool thing!
If you want the ability to group tests in different ways, across namespace boundaries, you can use categories to do it. It's not as easy of course.
An alternative, if you are using the command-line console runner, is to list the fixtures you want to run in a file and use the --testlist option.
Building off of Charlies post from above - The way I was able to set this up was using the --testlist option.
First create a testlist.txt file and store it somewhere in your solution. Structure the file in such a way so if you have a class like.
namespace NamespaceA
{
class TestGroup
{
[Test]
public void TestOne()
{
}
[Test]
public void TestTwo()
{
}
}
}
the files contents would look like this..
NamespaceA.TestGroup.TestOne
or for both..
NamespaceA.TestGroup
Then just your standard consule runner command
"nunit-console.exe" "path/to/.dll" --testlist="path/to/testlist.txt"
:D)
I am a complete beginner in java/eclipse/programming. I want to test small parts of my code to see if they are functioning in the way I want them to.
It is not intuitive to me from my first impressions of the program if/how I can run subsections of code. I also haven't yet found the answer to this problem online.
1) In eclipse, is it possible to highlight a couple of lines of code and view the output they would produce in the console?
2) If so, what are the step by step instructions to do this?
EDIT: I am running eclipse 4.7.0
Create a .jpage Scrapbook page (see Eclipse help: Creating a Java Scrapbook Page):
(via https://twitter.com/EclipseJavaIDE/status/882560433588240384)
The best way to do this is to keep your code modular or in other words make sure the different parts of your code are different functions. This way its simple to just run each function individually from your main function. In Java the main function is required so everything that you want to run has to somehow be triggered from whats in your main function.
Example in pseudo code:
some function{
code you want to run
}
other function{
other code you want to run
}
main function{
some function()
otherfunction()
}
I want to write a code generator that generates a class based on the meta model of another ceylon class. I want the code generator to run at compile time. What is the best way for me to do this. I could probably accomplish this by writing a plugin for gradle or the ceylon build system but I'm hoping for a simpler solution. Unfortunately, I don't see any support for code generators in ceylon. Also, are there any plans for code generators in ceylon?
I want to write this code generator because I'm thinking about writing a simple web framework for ceylon that look at a class like the following using the meta-model:
controller
shared class Controller() {
shared void doSomething() => print("did it!");
}
I plan for it to be like Spring MVC. This framework would make a restful API from the Controller class that allows someone to write an AJAX call like this:
$http.get("/Controller/doSomething");
I want to make things more convenient, high level, and simple by doing something like GWT. I want to create a code generator that automatically generates a class like this:
shared class RemoteController() {
shared void doSomething() {
$http.get("/Controller/doSomething");
}
}
The RemoteController would be run in a user's browser as javaScript and allow client side ceylon code to do an Ajax call like this:
RemoteController().doSomething();
That would end up calling the Controller().doSomething() on the server so "did it!" would be printed.
AST Transformers have been proposed, but are still in the early design phase. For now, to do compile-time code generation, you’ll have to rig up something of your own.
To actually generate the code, I would recommend use of ceylon.ast and ceylon.formatter. The workflow would roughly be:
analyze source code –
either parse it with ceylon.ast (ceylon.ast.redhat::compileAnyCompilationUnit) and analyze it without typechecking,
or parse it using the compiler, run the typechecker, then convert it to ceylon.ast (ceylon.ast.redhat::anyCompilationUnitToCeylon), keeping the typechecker information using the new update hooks in the very soon upcoming 1.2.0 release
edit the source code AST to add your new code (using a custom ceylon.ast.core::Editor that injects new class definitions into the CompilationUnits), or perhaps create entirely new compilation units if the RemoteController lives in a different module
convert the ceylon.ast AST to a compiler AST and feed it into ceylon.formatter to turn the AST into code again (see here for an example of that)
Alternatively, if you integrate this into your build step, you could skip the ceylon.formatter part of step 3 and instead feed the converted compiler AST into the typechecker and rest of the compiler directly.
I'm using Eclipse and JUnit 4 while developing an application within a tomcat container. The container manages the connection to our Oracle database.
While testing with JUnit i've got the following problem: In the constructor of the test subject there is something like this:
public Subject() {
// stuff
FancySingleton.getInstance().getFancy("stuff");
}
Unfortunately the method getFancy() tries to execute a Query which it can't because JUnit does not run within the tomcat container and ends up in an endless loop.
My first idea was to out-commend the code. At second thought it appeared to be a bad idea. I could forget to remove the comments before committing.
My second idea was to highlight the code for eclipse so that it doesn't execute it while running a JUnit test. But it requires eclipse to support such a method.
At last i thought of something like preprocessor directives.
What is your idea? Just passing in a boolean to the constructor is imho not a clean way of dealing with such a circumstance.
You'd either mock FancySingleton, or you'd do it right and inject an implementation.
Just installed rails 3.1 rc1 and am trying to grok the best way to manage javascript with the new asset pipeline
By default all coffeescript is compiled into a single application.js file, this is a good thing.
Each seperate coffee script file is appended to the js file and wrapped in an anonymous function which is executed via the call method
A common scenario would be to use some jquery to turn various forms into ajax forms, update UI, etc...
Many of these scripts will be specific to a controller or action, I am trying to grok the 'conventional' way to handle this,
since everything is wrapped in an anonymous function how do I only execute just
the code for a particular controller / action, by default all of the anonymous functions are being executed
I did play around with some hacks where I load the controller and action name into js variables and then in
coffeescript check those to conditionally run code, I don't like that very much
my initial thought was that each coffee file would contain a js namespace/object and I would call the specific ones from the view,
going to spike this using the default_bare = true configuration
see How can I use option "--bare" in Rails 3.1 for CoffeeScript?
EDIT
Looking around some more: this looks like it might be the correct approach - "Can't find variable" error with Rails 3.1 and Coffeescript
There are two common approaches:
Make behavior conditional on the presence of a particular element. For instance, code to run a signup sheet should be prefaced with something like
if $('#signup').length > 0
Make behavior conditional on a class on the body element. You can set the body class using ERB. This is often desirable for stylesheets as well. The code would be something like
if $('body').hasClass 'user'
gistyle is a simple gem that helps you running action-specific javascript codes.
By following its setup, you set some data attributes in your body element, representing the current controller and action names. Then it will only call that action when the corresponding view is loaded.