I am having few web services and working good with soapUI tool. I am trying to run as a suite. I have soapUI, junit and all other necessary libraries added to eclipse and system path has been setup to : soapUI.Junit = C://Doc and Sett/mkd/soapUI 4.2/bin/.
I have written #Before, #Test and #after methods. In #Test I have code something like below:
#Test
public void somex() {
SoapUITestCaseRunner runner = new SoapUITestCaseRunner();
runner.setProjectFile( "src/dist/sample-soapui-project.xml" );
runner.run();
}
But this code doesn't work. It is not able to recognise SoapUITestCaseRunner. Can someone help me with solution, please.?
you should add soapui-a.b.c.jar(e.g. soapui-2.0.2.jar) to the classpath.then problem will be solved.
Related
I am using Eclipse Oxygen.3 Release (4.7.3). The following is my JUnit test class:
import static org.junit.Assert.assertEquals;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
class MyMathTest {
MyMath myMath = new MyMath();
#Before
public void before() {
System.out.println("Before");
}
#After
public void after() {
System.out.println("After");
}
#Test
public void testSum_with3numbers() {
System.out.println("Test1");
int result = myMath.sum(new int[] {1,2,3});
int expected = 6;
assertEquals(expected, result);
}
#Test
public void testSum_with1numbers() {
System.out.println("Test2");
int result = myMath.sum(new int[] {3});
int expected = 3;
assertEquals(expected, result);
}
#BeforeClass
public static void beforeClass() {
System.out.println("Before class");
}
#AfterClass
public static void afterClass() {
System.out.println("After class");
}
}
When I run this Junit test, eclipse keeps popping up dialog telling "No tests found with test runner 'JUnit 5'". Why?
Your test class is currently based on JUnit 4 since it uses annotations from the org.junit package.
Thus, to get it to run as a JUnit 4 test class in Eclipse, you need to select the JUnit 4 Runner in the "Run Configuration". Click on the tiny arrow (pointing down) next to the green circle with a white arrow in it (at the top of the Eclipse IDE). There you should see your test class, and by selecting that you can switch between the JUnit 4 and JUnit 5 runners.
On the other hand, if your goal is to write a test using JUnit Jupiter (i.e., the programming model for JUnit 5), you'll need to switch from annotations in org.junit to org.junit.jupiter.api.
I had the same error, after trying everything, I have realized that the JUnit library wasn't added. So after adding it, tests worked as intended.
This happened to me because my test method was declared as private and JUnit could not detect it. After I made it public it worked as expected, of course with #Test annotation.
In Eclipse 2019-09 (4.13) is a bug that can cause the "No tests found with test runner 'JUnit 5'" error:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=551298
I added the following dependency to my project and it worked for me:
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version><!--$NO-MVN-MAN-VER$-->
<scope>test</scope>
</dependency>
the test class is not public, make it public and it should work
Take a look back to your imports.
You imports import org.junit.Test; (Used for run test cases with JUnit 4)
You need to import import org.junit.jupiter.api.Test; to run tast case with JUnit5.
You are using JUnit 4 annotations with JUnit 5 dependencies.
If you want to use JUnit 5 you should replace:
#Before with #BeforeEach
#After with #AfterEach
#BeforeClass with #BeforeAll
#AfterClass with #AfterAll
#Ignore with #Disabled
Here is more about JUnit 5 annotations https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations/
Right click the java file and choose:
Build Path -> Configure Build Path -> Java Build Path.
Choose the tab Libraries in Java Build Path, On the right side tab choose Add Library.
Select JUnit and click Next.
Choose JUnit 5 in JUnit Library version dropdown and click finish.
Now run the Test with Junit Test, it will work.
This procedure worked for me.
right click and run as -> config-> make this change and run it will works cheers!!.
My 2 cents:
Right click on project -> Configure -> Add module-info -> Give some random name.
It should automatically add there a requires in the JUnit package, if not, then manually add this:
requires org.junit.jupiter.api;
And it will magically work!
* tested on Eclipse 2018-12
My issue was that, Run works fine, debug throws this error.
I was getting this merely because of low memory in the system. Ideally, eclipse couldn't launch the debug session due to low memory in the system. Error message thrown is confusing.
Hope it helps someone!
In my current case, I encountered this error when testing the pact verification on the Service Provider side.The error was thrown because the Pact Broker doesn't have any pact to test against the Service Provider.
Visit the pact broker and ensure that there is at least one pact to test with.
I had the same problem with an Eclipse (2020-09) non-Maven project. None of the proposed solutions worked, but changing the compiler from 9.0.4 to 15.0.1 did.
I did that by selecting Preferences > Java > Installed JREsand checking the box next to jdk-15.01. You may need to install a recent JDK if none are shown.
Adding the JUnit vintage dependency fixed the issue for me.
https://junit.org/junit5/docs/current/user-guide/#migrating-from-junit4-running
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
I have a script written in Selenium using the TestNG framework. This script executes via an xml file. Since we do not have main method in this, how can I export this script to a runable JAR file?
I marked this question as a dupe (and this code snippet comes from the dupe question), but basically you could write a public static void main method that scans for tests or loads a existing testng.xml file. Then, you just need to use something such as Maven Shade plugin to package it.
public static void main(String[] args) {
TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { test_start.class });
testng.addListener(tla);
testng.run();
}
I used WebDriverManager project to manage my driver libraries. I would have the .jar load those externally.
For some reason when I open a new solution Resharper always refuses to find unit tests. I spend half an hour struggeling/rebuilding/poking until suddenly Resharper magically finds my unit tests. Once they are found it runs them fine every time.
Test example:
using NUnit.Framework;
namespace NamespaceOfTheCodeToTest.Test
{
[TestFixture]
public class FunctionalityTest
{
[Test]
public void Scenario_Input_Result()
{
}
}
}
I am using RESHARPER->Unit Tests->Run All Tests from Solution
What am I doing wrong here?
It seems the problem was NUnit test adapter was not installed. After installing that visual studio extension all tests where found instantly.
Edit: a better solution is to use "Run Unit Tests" on the test project, folder with test projects or solution.
I am following a book called "The Art of Unit Testing". I have reached a point where I need to test my test method that I have writtent using NUNit. The author instructs to build the project and then locate the path to the assembly file that was built and give the path to NUnit for testing.
My problem is that I cant seem to get this Assembly file path. Where is it located?
Plus, when I run my code, I am getting the following error:
Error 2 Program 'c:\Users\Documents\Visual Studio 2012\Projects\Loganalyzer\Loganalyzer\obj\Debug\Loganalyzer.exe' does not contain a static 'Main' method suitable for an entry point c:\users\documents\visual studio 2012\Projects\Loganalyzer\Loganalyzer\CSC Loganalyzer
Here's my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Loganalyzer
{
public class LogAnalyzer
{
public bool IsValidLogFileName(string fileName)
{
if (!fileName.EndsWith(".SLF"))
{
return false;
}
return true;
}
}
}
I am following the exact example that's in the book but cant get it to work as you can see. I will appreciate your help folks.
using Loganalyzer;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LogAnalyzerTest
{
[TestFixture]
class LogAnalyzerTest
{
[Test]
public void IsValidFileName_validFile_ReturnsTrue()
{
//Arrange ( Arranges objects, creating and setting them up as necessary).
LogAnalyzer analyzer = new LogAnalyzer();
//Act
bool result = analyzer.IsValidLogFileName("whatever.SLF");
//Assert ( Asserts that something is as expected)
Assert.IsTrue(result, "file name should be valid");
}
}
}
It seems as though you're trying to run your class project Loganalyzer, but you'll probably be wanting to use some sort of test runner. I prefer TestDriven.net.
NUnit is just the testing framework (very simplified, it specifies the rules for how to set up tests, etc).
What you need is some application or plugin to actually run them. You run the tests in the concole runner, or the GUI runner that come with NUnit for example, or in TestDriven.net (which I've heard is excellent).
Personally, I use the runner that comes with Resharper (although that is only free to try for a month or so).
The point is that you don't have an executable project, but rather a class library, containing stuff to test. The runner runs your tests, which in turn, call your code.
If you want to use the native nunit runner you typically use a class like this
static class NUnitLauncher
{
[STAThread]
static void Main()
{
AppEntry.Main(new[] { Assembly.GetExecutingAssembly().Location });
}
}
You'll also have to have it set as the start-up object (in the project's properties).
You'll also need to reference nunit-gui-runner.dll which you can find in the nunit install directory (normally program files). Mine is at
C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\lib
The native nunit runner has it's problems but I find the resharper (6.1) test runner is unstable when debugging - it sometimes bombs out randomly. It also doesnt understand all the different types of parameterised tests you can have in nunit. Hopefully this isnt the case in the newer versions - it's got a much nicer UI.
The problems you describe above are two seperate things - one sounds like it is because you dont have a startup object set; the other sounds like it is confusion about what an assembly is. The executable that gets produced when you compile will contain an assembly - if you point nunit at that then it should work (assuming it has some nunit stuff in there (eg stuff tagged up with [Test] etc))
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