I am trying to setup unit testing using codeception. I have followed the guide and have the following:
unit.suite.yml:
class_name: UnitTester
modules:
enabled: [UnitHelper, Asserts]
When I try to run codecept build, I get the following exception:
[Codeception\Exception\Configuration]
UnitHelper could not be found and loaded
UnitHelper is not a built-in class, but a helper class generated for unit suite.
You have to execute this command to create it:
codecept generate:suite unit Unit
Related
I am using Gradle 7.6, Karate 1.3.1, Java 17.0.5 and Junit 5.8.1.
I want to configure a Jenkin job for each feature to create a health check monitor. I need gradle commands to run feature files using tags #smoke, #regression, #featureName etc.,
I have tried with the following command, it worked earlier and stopped working recently.
./gradlew test -Dkarate.options="--tags #smoke" -Dtest.single=TestRunner#testTagsWithoutFeatureName
Where TestRunner is the following Java class
import com.intuit.karate.junit5.Karate;
public class TestRunner {
#Karate.Test
Karate testTagsWithoutFeatureName() {
return Karate.run().tags("#smoke").relativeTo(getClass());
}
}
My advice is use the Runner class, that is better designed for running tests in CI. The JUnit helpers are just for local-dev convenience: https://stackoverflow.com/a/65578167/143475
It should be possible to even pass a feature to karate.options as the last argument. Which might be more convenient than writing a Java class for every combinations. You should experiment.
Otherwise no suggestions, but if you feel there's a bug, follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
How to run the JUnit test suite containing a set of test cases(groovy based) from the command line. Following is the test suite class generated by eclipse.
package com.example.testclasses;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
#RunWith(Suite.class)
#SuiteClasses({ abc.class, xyz.class })
public class AllTests {
}
The above test suite works when I run the above test suite(AllTests)as JUnit from eclipse, however, I want to run the test suite(AllTests) from the command line. How do I do this?
Info: I am using Geb(Groovy) based testing where all the test cases(example: abc, def) are groovy based(having .groovy extension).
If you wish to run your tests from the command line I would suggest using a build system. My personal choice would be to use Gradle but you could probably also get away with using Maven.
The benefit of using a build system, apart from being able to run the tests from the command line, is that it will help you manage your dependencies and it will be easier to build the project for others working on the same codebase - they won't have to manually setup all the dependencies and their versions in the IDE.
Try this:
java -cp /path/to/groovy/embeddable/groovy-all-1.8.1.jar groovy.lang.GroovyShell AllTests.groovy
where 1.8.1 should be replaced with your version of groovy-all-*.jar
How to run just one method of a test case for debugging with Gradle? I have tried:
gradle test -tests example.TestFoo#testMethod1 --debug-jvm
but it ends up with following error:
No tests found for given includes: example.TestFoo#testMethod1
The test TestFoo class has testMethod1(), testMethod2(), etc.
Use . instead # in your tests filter expression to point to a method name:
gradle test --tests example.TestFoo.testMethod1 --debug-jvm
You can find more examples on filtering tests in 48.14.3. Test filtering documentation section.
I make my first steps in creating functional tests with codeception.
This is my functional.suite.yml
class_name: FunctionalTester
modules:
enabled:
- PhpBrowser:
url: 'http://localhost'
- \Helper\Functional
Now I want to generate the actions for the FunctionalTester. I use this command:
vendor/bin/codecept build
No methods are added. I expected that methods like amOnUrl($url) are created in the trait FunctionalTesterActions. But this is my result.
Building Actor classes for suites: unit, acceptance, functional
-> UnitTesterActions.php generated successfully. 0 methods added
\UnitTester includes modules: Asserts, \Helper\Unit
-> AcceptanceTesterActions.php generated successfully. 0 methods added
\AcceptanceTester includes modules: PhpBrowser, \Helper\Acceptance
-> FunctionalTesterActions.php generated successfully. 0 methods added
\FunctionalTester includes modules: \Helper\Functional, REST, PhpBrowser
The configuration should be OK. I tested this with the command
vendor/bin/codecept config:validate
What is my mistake? Thanks for every hint.
I figured it out. Turns out I had a syntax error in my Helper.
Hope this helps someone in the future.
In order to automate test cases with java using testNG and Appium :
How can i generate a script that contain common configuration of capabilities and all the setup for my tests to avoid writing a setup method in each class and run it with the same manner as when i run appium by npm with protractor scripts
This is the following code i use to run appium with protractor by console :
appium --default-capabilities '{"app":"safari","browserName":"safari","appium-version":"1.5.1","platformName":"iOS","platformVersion":"9.3","deviceName":"iPad Air","nativeInstrumentsLib":true}' --command-timeout "0" --pre-launch --nodeconfig "/Users/me/nodeconfig.json" --launch-timeout "180000"
Another question : How can i use only console with testng test and eliminate the use of eclipse IDE as i'm doing with protractor all my test written with console in vi mode in Mac ?
For java using testNG and Appium:
create a base class where you will set the appium driver with all the capabilities and than extend this base class to get the appium driver.
u can also do this by invoking that class constructor. U can go through this sites to get idea:
http://toolsqa.com/selenium-webdriver/constant-variables/
http://blog.xebia.in/2016/01/11/Design-Patterns-in-Selenium-Automation-Part1-POM/