Mocha Custom Reporter - Pass in values - testing

I have written a custom reporter for mocha. I would like to be able to pass in variables to it, is there a way to pass in variables?
For example, I would like to pass in a Project and a suite. My custom reporter then is able to report these results to a 3rd party application, but I need to be able to report the suite and project in the test pass or test fail methods.
Thanks

Related

Pass Fixtures dynamically on Cypress

I had a question regarding the fixtures which I wasn't able to find in the docs. Can we pass the a particular JSON fixture in the command line. For example, I have two json files user1.json and user2.json and on runtime I want to pass the fixture I require for the test.
Can I do something like npx cypress run --fixture name that dynamically passes the json file.

Configuration of a JUnit 5 extension

I am upgrading an internal tool based on JUnit 4 to JUnit 5. Therefore I have to write an extension for the test execution. The task of the extension should be to ensure the correct state of external application (start it if it is not running etc.). To perform this task serveral parameter (from the commandline) are needed.
Can I store these parameters in the extension context? And if so, how can I access it before the actual tests run starts?
Can I store these parameters in the extension context?
You could, but a better option would simply be to access them as "configuration parameters" -- for example, via org.junit.jupiter.api.extension.ExtensionContext.getConfigurationParameter(String).
And if so, how can I access it before the actual tests run starts?
You can access them via the aforementioned ExtensionContext.getConfigurationParameter(String) method within a BeforeAllCallback extension.
If you want that custom extension to be executed before all test classes without the user having to register the extension explicitly, you could have the extension registered automatically. See the User Guide for details.

Injecting test classes created by Platform Launcher

I'm running JUnit 5 tests programmatically (Kotlin):
LauncherFactory.create().execute(
LauncherDiscoveryRequestBuilder
.request()
.selectors(
DiscoverySelectors.selectClass(Sometest::class.java)
)
.build(),
SummaryGeneratingListener()
)
Is there any way to hook into the Launcher's lifecycle to inject test classes with something before the tests are run?
I'm trying to use #ExtendWith, but then my TestInstancePostProcessor is still created by JUnit, whereas I need a link to my original scope, from where I execute the Launcher.

Cannot spy on Titanium.Network methods with Jasmine

I'm using Jasmine to write tests for a Titanium project. I have a custom util js to provide me information about the network availability.
In this util there is a helper method calling Titanium.Network.getNetworkType() to retrieve the current active network type. The action I do depends on the network type retrieved by this call. To ensure test coverage on this, I'm writing Jasmine tests. But unfortunately I'm having issues with spying on Titanium.Network.getNetworkType()
Code snippet:
console.log(Titanium.Network.getNetworkType()); // returns 1
spyOn(Titanium.Network, 'getNetworkType').andReturn(666);
console.log(Titanium.Network.getNetworkType()); // returns 1
Spying on a method of Titanium (e.g. getApiName()) does work. Any ideas on this?
Thanks.

How to integrate Galen reports in Jenkins

I've started to use Galen framework to test the layout of my website pages and I also have my other test, written in Selenium, integrated into Jenkins.
I'm using Java+JUnit+Maven and I would like to know if anyone has managed to integrate the Galen reporting into Jenkins and how.
Because for the moment I am using something like:
assertThat(layoutReport.errors(), is(0));
which tells me if there were errors in the tests but not where.
Thanks!
P.S. If someone with reputation could make the tag galen-framework so that we can group these type of questions, it would be great :D
In your case you could use Galen for generating HTML reports as it normally does when you run tests with it. Though you will have to manage the creation of GalenTestInfo objects.
Here is how the HTML report generation works. Imagine you have somewhere obtainAllTests method defined which returns a list of all executed tests.
List<GalenTestInfo> tests = obtainAllTests();
new HtmlReportBuilder().build(tests, "target/galen-html-reports");
Somewhere in your code you could create a GalenTestInfo and add it to some collection:
GalenTestInfo testInfo = GalenTestInfo.fromString("Here goes the name of your test");
Once you have done the layout checking and obtained LayoutReport object you could add this report to the report of the test. Here is how you can do it:
LayoutReport layoutReport = Galen.checkLayout(driver,
specPath, includedTags, null,
new Properties(), null);
testInfo.getReport().layout(layoutReport, "A title for your layout check");
You can find more insights in this project https://github.com/galenframework/galen-sample-java-tests. It has a basic setup for Galen tests in Java + TestNG + Maven. The reports in it are collected in a singleton GalenReportsContainer. There is also a reporter implemented in GalenReportingListener which takes all those tests from GalenReportsContainer and generates HTML reports.
You can see a full example for Java (TestNG and JUnit) and JavaScript here:
https://github.com/hypery2k/galen_samples.
I use the HTML Plugin together with Jenkins, see example here