I use Eclipse PDT for PHP.
I can run my PhpUnit tests : works fine.
But I can not debug my unit tests.
Has someby already done this ?
Can somebody help doing this ?
Thanx,
Messaoud
An example is more worth than 1000 words :
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
class MyTestCase extends PHPUnit_Framework_TestCase {
protected function setUp() {
parent::setUp ();
}
function testSimple() {
echo "horray !";
}
protected function tearDown() {
parent::tearDown();
}
static function main() {
$suite = new PHPUnit_Framework_TestSuite( __CLASS__);
PHPUnit_TextUI_TestRunner::run( $suite);
}
}
if (!defined('PHPUnit_MAIN_METHOD')) {
MyTestCase::main();
}
the key thing is :
provide a main method in your testcase
test if the test is executed directly (via php MyTestCase.php) or by phpunit itself. if executed directly - just start the testrunner.
know you can debug your testcase.
We can solve this issue with our Eclipse plugin MakeGood.
MakeGood provides a simple way to debug your tests. You only run a test in Debug Mode.
For more information, see the user guide.
For others who are wondering if there are simple instructions for configuring Eclipse/Aptana with phpunit, here's a website I have found:
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit
What you have to do basically is:
Make sure your PEAR libraries are in your project's include path. Right click on the project in the navigator window and click Properties. You'll see there's a section for PHP Include Path (or PHP Build Path in Aptana for my version), open that and add your PEAR libraries to your include/build path so that Eclipse knows about phpunit.
Create a debug configuration which runs the phpunit.php file (you might need to add the .php extension to the file if it is running with a shebang, as the case is in Mac OS X).
So with phpunit.php file as the "Start Action" script, set "PHP Script Arguments" so that the PHPUnit testing file you are interested with is run by phpunit.php. Add any other command line arguments, to suit you. eg. --verbose is a good option. You can also use variables like ${resource_loc} to have Eclipse replace it with the current file for example.
Run your debug configuration and enjoy debugging!
You do not need to modify your test files or anything, they'll work out of the box.
I finally run debugging parallel to command line in eclipse 3.4. Debugging i run as "PHP web page", my minimal code
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
class XTest extends PHPUnit_Framework_TestCase{
public function testX(){
//...
}
}
if (!defined('PHPUnit_MAIN_METHOD')) {
header('Content-type:text/plain; charset=utf-8');
PHPUnit_TextUI_TestRunner::run( new PHPUnit_Framework_TestSuite( 'XTest'));
}
I have confirmed by setting a breakpoint in my setUp() method inside my unit test by following the instructions here:
How to Debug Your PHP Unit Tests in Eclipse
It involves copying the /usr/bin/phpunit file to your project (so it's accessible through eclipse's GUIs), and add the .php extension to it. From there, goto your debug configs and set the PHP-File to that phpunit.php file.
The next important step worked great for me, because I'm using Yii which provided me with a bootstrap.php file. Put something like this in your args:
--bootstrap=${workspace_loc}/my-project/trunk/protected/tests/bootstrap.php ${workspace_loc}/my-project/trunk/protected/tests/unit/SomeClassToTest.php
Related
I'm trying to run a simple java test code. I'm getting a "can not find or load main class file "(something like that)
The tutorial I'm following uses this command
-> javac name.java (javac doesn't work, using ->java ..)
-> dir (shows the classname as a file)
> java classname
> outputs "hello world"
I can't seem to get past the ->java running.java
class apples //everything begins with a class - need this to do anything
{
public static void main(String args[])//method
{
System.out.println("Hello World");
}
}
There could be a few problems here. Check the following:
Are you saving the file as the name of the class plus .java, e.g. apples.java
When you execute it, are you typing the name of the class or the name of the class file? you should be typing java apples, not java apples.class or java apples.java.
EDIT:
I Noticed you haven't compiled the program using javac, which makes the progrm unrunnable by java [program_name]. You need to run javac [java_sourcde_file_name] to generate a .class file. If javac doesn't work, maybe:
You don't have the JDK (Java Development Kit) installed and should download it from Oracle
javac is not in your PATH - unlikely but possible - see http://www.apl.jhu.edu/~hall/java/beginner/settingup.html.
javac runs properly but your program doesn't compile properly. this seems unlikely given the program you posted looks fine.
class Apples //- need this to do anything
{
public static void main(String args[])//everything begins with a method
{
System.out.println("Hello World");
}
}
Make sure you are in current directory of java file
compile as
javac Apples.java
Run as
java Apples
Before working in it , should need to know the coding convention it would be better to work java
Well. All you have to do in Jaca is navigate you where your class files are stored and then use java "class name". You DO NOT need to put .java or .class. Just the name.
change your class name from apples to Apples (naming convention for java class names):
http://en.wikipedia.org/wiki/Naming_convention_%28programming%29#Java
also recommend you to change the file name accordingly...
then recompile and run it
javac Apples.java
java Apples
cheers
I have the following code:
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testCalculate()
{
$this->assertEquals(2, 1 + 1);
}
}
?>
When I open the PHP file in the browser, I get the following error:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found
However, if I use the command line it works fine:
phpunit [local_path_here]/testcase.php
Result:
.
Time: 0 seconds, Memory: 5.00Mb
OK (1 test, 1 assertion)
Why is that? How can I make it to run it in the browser as well?
You can integrate add-on for running unit tests via native web GUI:
https://github.com/NSinopoli/VisualPHPUnit
You can't run unit tests in the browser. Maybe in the future: http://sebastian-bergmann.de/archives/638-PHPUnit-3.0.html#c4983
If you want to view the code coverage run
phpunit --coverage-html=coverage testcase.php
and then open the index.html file in the coverage directory.
Otherwise, you have to run your tests from the command line.
You may have a different include path on the command line. Check to see whether you have a php-cli.ini file in addition to the normal php.ini file. The first one will be used when you run PHP from the command line. That's probably got a different include_path setting. It might include the PEAR directory, for example, if PHPUnit was installed via PEAR.
You can use eclipse also to run phpunit.
follow the link below
http://pkp.sfu.ca/wiki/index.php/Configure_Eclipse_for_PHPUnit
I have the following class and unit test in a PHP project in Eclipse:
I know my unit test works as I can run it at the command line:
Now I want to run this test from Eclipse. I set up PHP Unit in Eclipse like this:
However, when I run the PHPUnit tests:
It tells me that it can't include the class file:
/usr/bin/php -c /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/zend_debug/session4910937990995915704.tmp -d asp_tags=off /Applications/eclipse/plugins/org.phpsrc.eclipse.pti.tools.phpunit_0.5.0.R20101103000000/php/tools/phpunit.php --log-junit /var/folders/UA/UAv38snBHd0QMgEPMCmM9U+++TM/-Tmp-/pti_phpunit/phpunit.xml /Volumes/data/domains/et/extjslayout/phpunittest/tests
PHP Warning: include_once(../Product.php): failed to open stream: No such file or directory in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Warning: include_once(): Failed opening '../Product.php' for inclusion (include_path='/usr/local/PEAR') in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 3
PHP Fatal error: Class 'Product' not found in /Volumes/data/domains/et/extjslayout/phpunittest/tests/ProductTest.php on line 9
Why would PHPUnit be able to find the class when run from the command line but not when run from Eclipse?
When you start something from the command line, the "current directory" has a well-defined meaning: It's the directory where you started the command.
In Eclipse, what is the "current directory"? It's probably the directory from which you started Eclipse or maybe the folder in which Eclipse is installed.
I haven't used PHP in Eclipse before but for other languages, I can set the current directory in the launch config somewhere. If that doesn't work, define a variable which points to your project and then use absolute paths (using that variable as a starting point).
Have same problem. Found only solution by creating tests with internal PHPUnit wizard like at this screenshot:
Source: HowTo create a Test Case Class from a PHP Class
But following investigate show that your test case file should contain reference to tested code for example like this: require_once 'C:\Apache2\htdocs\jobeet\src\Ibw\JobeetBundle\Utils\Jobeet.php';
Other experiments with plugin config not bringing luck. So in my opinion PHPUnit from PHP Tools not well developed plugin. Consider using MakeGood plugin as better alternative.
I have installed Eclipse 3.5.2 and today's Scala plugin from /update-current (that's Scala 2.8 final.) I can compile and run Scala projects consisting of a single singleton object that implements main().
But, if a project contains more classes, I receive the "Could not find the main class" error.
I have tried searching for the solution and I discovered:
Eclipse is correctly looking for the Main$ class, not the Main class
* under Debug Configurations, my main class is correctly identified as mypackage.Main
* my plugin is up to date and recommended for my version of Eclipse
* cleaning, restarting etc. doesn't help.
The same project will compile with scalac.
Thanks for any ideas on how to solve this.
EDIT: MatthieuF suggested I should post the code.
This snippet produces an error. It's not the most idiomatic code, but I wrote it that way to test my environment. I tried it as a single file and as separate files. It DOES work with scalac.
import swing._
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
object Hello {
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
BUT, if I nest the definition of HelloFrame within Hello, it works. This snippet runs perfectly:
import swing._
object Hello {
class HelloFrame extends Frame {
title = "First program"
contents = new Label("Hello, world!")
}
val frame = new HelloFrame
def main(args : Array[String]) : Unit = {
frame.visible = true
}
}
For me, the problem was that there was a build error (see Problems tab) which was preventing compilation; oops! The reason you see the error is that the run macro proceeds despite the failed compilation step, and attempts to run class files it expects to be there; they don't exist because there was a build error preventing compilation, so it says it can't find Main (not compiled).
Problem goes away when build can complete successfully, i.e. errors are fixed.
I guess, theoretically, there may be more complicated reasons your build is not completing successfully that are not listed in Problems.
One possibility is that you are trying to launch using ctrl-F11, but from a different class.
The Scala Eclipse plugin does not obey the defaults for Java launching. In Preferences->Run/Debug->Launching, there are some options Launch Operation->Always Launch the previously selected application, etc. This currently does not work in the Scala eclipse plugin. To launch a specified main, you need to launch it from the editor for the class.
There has been a bug raised for this. http://scala-ide.assembla.com/spaces/scala-ide/tickets/1000023-scala-launch--does-not-follow-jdt-behaviour
EDIT: This is now (mostly) fixed.
For me it was Eclipse specific problem. I noticed that .class file wasn't built at all. So bin directory doesn't have compiled classes.
When I manually compiled *.scala file using *.sbt and copied it to bin directory it was working as expected.
I tried different tips and tricks and it wasn't worked until I reinstalled Scala plugin in Eclipse .
I'd solve similar problem by executig "Project->Clean.." with next automatically building.
I had the same error message with a Java application made by myself.
The problem was that I deleted (though inside Eclipse) a jar that belonged to the Java build path, without deleting it from the Java build path (project's Properties window). When I did it the class could compile and run again.
Make sure that the .class files exist, usually below the bin directory.
In particular, if you have errors in unrelated files in the same project then the compilation may fail, and no .class files will be produced.
There can be the case of projects, containing errors, added to the build path of the application which prevents the completion of successful compilation. Make sure you remove any such project from the build path before running the application.
Removing these projects solved the problem for me.
Do you have a proper build tool setup? Like sbt have you installed it?
You can check its version by $sbt --version
If it is not setup you can download from here http://www.scala-sbt.org/download.html
You might have to restart your eclipse after installation.
Just copy your XXX.scala file code. Remove the package and create a new Scala Class. Paste your XXX.scala code. (If you are using maven, do a maven clean and build.) Run configuration again. This works for me.
I have faced this issue. I have just deleted the package name, created scala class, Written the same code, Set Build to "Build Automatically". Finally, It works perfectly fine.
Check scala-ide.log
For me the issue was that there were errors on:
AppData\Local\Temp\sbt_10d322fb\xsbt\ClassName.scala:16: error: not found: value enteringPhase
enteringPhase(currentRun.flattenPhase.next) { s fullName separator }
If you are using Intellij, mark directory as source root
I'm trying to run a GWT unit test in a sample app. I ran
cmd /c /java/gwt-windows-1.6.4/webAppCreator.cmd -out gwttasks com.gwttasks.GwtTasks
Copied in junit-4.5.jar into a lib directory, and added that to the classpath.
Ran:
cmd /c /java/gwt-windows-1.6.4/junitCreator.cmd -junit lib/junit-4.5.jar -module com.gwttasks.GwtTasks -eclipse GwtTasks com.gwt
tasks.unit.GwtJunit
When I try to run any of the generated cmd file (such as GwtJunit-hosted.cmd) or any of the launch files, I get the following error. All the web pages I've seen say to add the test source to the classpath, but it's already there, so that's not the problem. Anyone else seen this?
com.google.gwt.junit.JUnitFatalLaunchException: The test class 'com.gwttasks.unit.GwtJunit' was not found in module 'com.gwttasks.GwtTasks'; no compilation unit for that type was seen
at com.google.gwt.junit.JUnitShell.checkTestClassInCurrentModule(JUnitShell.java:390)
at com.google.gwt.junit.JUnitShell.runTestImpl(JUnitShell.java:626)
...
The answer could be found here :
http://raibledesigns.com/rd/entry/testing_gwt_applications
In netbeans I added the src/java and test to the class path and debugging worked!!!!!
THANKS
I just want to add that I had the same problem, because I did the (very silly) mistake to not put the GWTTestCase class into the "client" directory, but into another one. No wonder it wasn't found ;)