My goal is to have a class which can find any tests written in kotlintest. I already have working code for Java/Scala/Groovy unit tests but can't get it to work for Kotlintest.
My discover code:
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request().selectors(selectPackage("com.example")).build();
descriptor = new KotlinTestEngine().discover(request, uniqueId);
UniqueId has value of "engine:junit-example". I tried adding the following code but it doesn't work either.
new DiscoverySelectorResolver().resolveSelectors(discoveryRequest, descriptor);
The descriptor contains all the classes with tests but no test methods. In other cases it is enough to call descriptor.getChildren() to get the test methods but with Kotlintest I get empty list.
Thanks for any help.
The reason your code doesn't work is because KotlinTest doesn't honour package name selectors. This could be considered a bug in KotlinTest.
It does honour classpath, class, directory and uri selectors though.
Edit:
As of 3.2 KotlinTest now supports package selectors so your code will work.
Related
Uncaught DOMException: Failed to execute 'define' on 'CustomElementRegistry': this name has already been used with this registry
at http://127.0.0.1:8000/components/#polymer/polymer/lib/elements/dom-module.js:175:16
Tried deleting node-modules and package-lock and reinstalling did not work.
this error is due to a custom element tag-name being registered which is already registered; to fix simply check that an element by this name hasn't already been registered. This example solution checks to see if something is already registered using the existing API and if not, registers the given Class (inheriting from/extending HTMLElement--at some point):
customElements.get('the-element') || customElements.define('the-element', HTMLTheElement);
For more on the API see https://developer.mozilla.org/docs/Web/API/CustomElementRegistry
most/mature libraries address this problem and those that don't, or are mangled by package and build process complexities can have it pop up; in most cases either updating to a current version, migrating to Lit (https://lit.dev) or patching the problem somehow provides a path to a solution; note the simpler solutions are far easier to maintain--as can be seen in the conflation of npm, polymer over the actual error in the original question; the Polymer project became lit-html and LitElement, and recently rebranded as "Lit" (and still includes these lit-things). Professionally I'm migrating away from npm and Nodejs to Deno with the aim of generally resolve the many problems related to npm and tooling insecurity and complexity, however this answer provides a more direct solution (understand the problem and fix directly, or update to the relevant latest solution which includes this somehow).
Well, this worked for me, with no Typescript warnings,
if (!customElements.get('the-element')) { customElements.define('the-element', HTMLTheElement); }
Hope someone will find this useful.
Cheers.
It is unwise to use the answers above. You want it to fail! The reason being is that your NPM should be deduping duplicate packages, so the fact that you see a certain component being defined on the custom elements registry more than once is a crucial error that you need to debug why the same component is registered more than once.
How to debug, in short, go to your browser, inspect element, network tab, refresh, figure out which files are both registering the same element. Then check in the initiator to see which files are loading those files. Then you get a way better idea of why your app is not resolving the same import to a single place (your deduped dependency).
One reason why you might face this problem is due to semver. If you have multiple different major versions of the same dependency, NPM cannot just dedupe all of the installations to your root node_modules. How you solve this is up to you. Some people use npm-aliases for their different majors of a dependency, some people implement a plugin in their build-tool to resolve paths to a single installation, etc.
For people that can't use #jimmonts answer because the issue is in one of their dependencies you can use the following snippet:
This happens for us, because a package we are using defines an element. But this package is used by multiple apps. And these apps, wouldn't you know it, interact. So customElements.define('x-tag', className) gets called multiple times. And the second time it does, it crashes the app.
function safeDecorator(fn) {
// eslint-disable-next-line func-names
return function(...args) {
try {
return fn.apply(this, args);
} catch (error) {
if (
error instanceof DOMException &&
error.message.includes('has already been used with this registry')
) {
return false;
}
throw error;
}
};
}
customElements.define = safeDecorator(customElements.define);
I was getting the same error. You may not have the same issue as me but I thought I would drop my solution here just incase someone runs into the same issue in the future.
I had two modules that both imported the same custom element module, one of the was importing Module.js and the other module.js. Now the browser saw this as two separate files because URLs can be case sensitive, except my server saw this as one file because it is not case sensitive (express.js) or at least it was able to resolve the path to the correct file even with the incorrect case. And so the browser saw two "different" modules both defining the same custom element, but when I searched my source code only one file was defining the custom element.
I had this problem and found out that I was calling on my boundle.js file twice. Since I was using Webpack and HtmlWebpackPlugin, HtmlWebpackPlugin added the reference to my boundled file to my index.html file where I had already referenced it by hand.
I developed a solution, thats overrite the define with a precheck before define. It works fine for me, just ad the 2 lines into your index.js
customElements.defineclone = Object.assign(Object.create(Object.getPrototypeOf(customElements)).define, customElements);
customElements.define = (name, element) => customElements.get(name) || customElements.defineclone(name, element);
I'm hosting a service using Windsor's WCF Facility, but I can't get UseSynchronisationContext and ConcurrencyMode set that one would normally do using the ServiceBehaviorAttribute. I've seen two options that apparently should work (but tried both to no avail):
Registering ServiceBehaviorAttribute as a Component for IServiceBehavior
Modifying the Description collection of Behaviors in the OnCreated configuration callback in the WCF registration.
A third method that I've tried is using AddExtensions, but that results in an exception because there's already a ServiceBehaviorAttribute (by default?) in the list of Behaviors. This is also the case with method 2, but in that case I can remove it and add a new one, or modify the existing entry.
It's really frustrating that there doesn't seem any documentation on this except a line stating 'Remove the ServiceBehaviorAttribute' from your services, apparently because it can conflict with the WcfFacility.
Can someone point me on how to properly do this? Any hint is appreciated!
Unfortunately I didn't properly test. Modifying the properties of the ServiceBehaviorAttribute in the list of Behaviors of the Description property in the OnCreated action actually works as intended.
Sample registration:
container.Register(Component.For<IWCFWarehouseServiceAsyncCallback>()
.ImplementedBy<WarehouseService>()
.AsWcfService(new DefaultServiceModel()
.AddBaseAddresses(baseAddress)
.OnCreated(host =>
{
var sb = host.Description.Behaviors.Find<ServiceBehaviorAttribute>();
sb.UseSynchronizationContext = false;
sb.ConcurrencyMode = ConcurrencyMode.Reentrant;
})
.AddEndpoints(WcfEndpoint.BoundTo(binding).At("WarehouseService"))));
I'm trying to write a test that needs both Robolectric 2.2 and PowerMock, as the code under test depends on some Android libraries and third party libraries with final classes that I need to mock.
Given that I'm forced to use the Robolectric test runner through:
#RunWith(RobolectricTestRunner.class)
...I cannot use the PowerMock test runner, so I'm trying to go with the PowerMock java agent alternative, without luck so far.
I have setup everything according to this guide but I'm facing a collision problem between classes required by the javaagent library and by robolectric through its dependency with asm-1.4. Both depend on
org.objectweb.asm.ClassVisitor
, but javaagent-1.5.1 ships with its own version where ClassVisitor is an interface while asm-1.4 version for the same namespace is an abstract class, with the corresponding error at runtime:
java.lang.IncompatibleClassChangeError: class org.objectweb.asm.tree.ClassNode has interface org.objectweb.asm.ClassVisitor as super class
I have even tried to modify the javaagent library jar to entirely remove the org.objectew.asm classes in there, but that doesn't work as ClassNotFoundException happens afterwards due to some other classes needed in the org.objectweb.asm package that only ship in the javaagent library jar, and not in the asm one.
Any ideas? According to examples out there the agent seems to work fine with, at least, the Spring test runner.
I had the same problem and while I didn't solve this problem as such, I wanted to share my approach, which removes the need for PowerMock (which is always a good thing in my view): I wanted to mock a call to
Fragment fooFragment = new FooFragment();
So what I did was addanother level of indirection. I created a FragmentProvider class:
public FragmentFactory fragmentFactory = new FragmentFactory();
[...]
Fragment fooFragment = fragmentFactory.getFooFragment();
After i did this, I could just mock out the factory with standard Mockito, like this:
FragmentFactory mockFactory = mock(FragmentFactory.class);
activity.fragmentFactory = mockFactory;
when(mockFactory.getFooFragment()).thenReturn(mockFooFragment);
I am using the free edition of SoapUI (version 4.6.1) with multiple workspaces. One of my frustrations is that SoapUI does not seem to support workspace-level custom properties.
The *-soapui-workspace.xml files I have reviewed contain an empty con:settings element (i.e. <con:settings/>). Same in the *-soapui-project.xml files I have reviewed.
My intuition & hope is that these elements allow workspace- or project-level additions to or overrides of settings I see in my general soapui-settings.xml file - e.g. additional global properties that I want when a given workspace is loaded.
However, when I create a settings file SomeService Tests-soapui-settings.xml that contains...
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-settings xmlns:con="http://eviware.com/soapui/config">
<con:setting id="GlobalPropertySettings#properties"><![CDATA[<xml-fragment xmlns:con="http://eviware.com/soapui/config">
<con:property>
<con:name>WorkspaceCustomPropertyTest</con:name>
<con:value>some value</con:value>
</con:property>
</xml-fragment>]]>
</con:setting>
</con:soapui-settings>
...and set the con:settings element in the SomeService Tests-soapui-workspace.xml file like so...
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-workspace name="SomeService Tests" soapui-version="4.6.1" projectRoot="${workspaceDir}" xmlns:con="http://eviware.com/soapui/config">
<con:description>Workspace to organize all SomeService test projects.</con:description>
<con:settings>SomeService Tests-soapui-settings.xml</con:settings> <!-- Reference the workspace settings file. -->
<con:project name="SomeService Authentication Tests">SomeService Authentication Tests-soapui-project.xml</con:project>
</con:soapui-workspace>
..., nothing happens.
I do not get an error upon loading the workspace, but I also do not get any indication that the con:settings element is doing anything either. For example, SoapUI Preferences > Global Properties does not list a WorkspaceCustomPropertyTest property.
I can keep tinkering of course, but an explanation of the workspace- and project-file con:settings elements would help.
Searching SO, the SmartBear SoapUI forum, and more broadly for an explanation of the workspace- and project-file con:settings elements has yielded nothing so far.
Can anyone explain how to use the workspace- and project-file con:settings elements?
Alternatively, can anyone shed light on how to achieve a similar result (i.e. workspace-level custom properties) with the free edition of SoapUI?
What about that?
Create a ini("myconfig.groovy") file("assuming that this file will be in the same directory of your project file"):
global_property='Global value'
Use this groovy script to grab the property:
// Script imports
import com.eviware.soapui.support.GroovyUtils
import groovy.util.ConfigSlurper
// Grovvy utils handle OS directories path abstraction
def groovyUtils = new GroovyUtils(context)
def config = new ConfigSlurper().parse(new File(groovyUtils.projectPath + '/myconfig.groovy').toURL())
// Just logging the property but you can set the property here
log.info config.global_property
Then you can add the value to the desired object at run time.
It doesn't seem possible to do it at the workspace level. You could do it at one of the testing levels, see: http://www.soapui.org/Functional-Testing/working-with-properties.html
SoapUI does support global properties.
In File> Preferences> Global Properties
Here you can assign Global Properties that spans all projects. Sadly, currently, it will be used for all work spaces. Hope this helps, having a groovy script to manually handle everything just seems a bit over kill to me.
I have a block of XAML of which i'm trying to deserialize. For arguments sake lets say it looks like below.
<NS:SomeObject>
<NS:SomeObject.SomeProperty>
<NS:SomeDifferentObject SomeOtherProp="a value"/>
</NS:SomeObject.SomeProperty>
</NS:SomeObject>
Of which i deserialise using the following code.
XamlReader.Load(File.OpenRead(#"c:\SomeFile.xaml"))
I have 2 solutions, one i use Unit Testing, and another i have for my web application. When i'm using the unit testing solution, it deserializes fine and works as expected. However, when i try to deserialize using my other project i keep getting an exception like the following.
'NameSpace.SomeObject' value cannot be assigned to property 'SomeProperty' of object 'NameSpace.SomeObject'. Object of Type 'NameSpace.SomeObject' cannot be converted to type 'NameSpace.SomeObject'.
It's as if it is getting confused or instantiating 2 different types of objects? Note, i do not have similarly named classes or any sort of namespace conflict. The same codes executes fine in one solution and not the other. The same project files are referenced in both.
Please help!
Resetting IIS seemed to have fixed the problem. XAML must have been using a shadow copy of the DLL's sigh