unit test cases for wizard in odoo 10 - unit-testing

I am new to Odoo. I am using Odoo 10. I would like to write test cases for a new wizard I created under a module A. I put all my wizard code (views + models) inside wizards directory. I created unit test cases under the path <<module/tests>> followed all the file/class/method naming conventions. When I try to upgrade the module (with test enable) to run unit test cases, all the other modules tests scripts are run but not for the newly created module A. Please suggest what additional changes might be needed to enable test scripts for a newly created module with wizard.
Thank you.

I believe that the structure you have follow is according to the standard way. You can find the structure here Testing Module Structure.
Also please check that the naming on the folder and file in which you wrote the code,
for example - tests/test_todo.py Also, don't forget to update the import in tests/init.py to from. import test_todo
This is because Odoo expects the test module names to start with test_ when it searches for tests belonging to a module Code Reference
Command to Run the testcases:
python ./odoo.py -i module_to_test --log-level=test -d your_database --db-filter=your_database --test-enable --stop-after-init

Related

Unit testing with Webpack, Jasmine (-core), typescript

I have a project that is using webpack to bundle all code into a single file. The project is using Typescript and it is working fine at the moment.
I've gone to add unit testing and jasmine seems to be the way (one of the many ways) forward. Its actually jasmine-core that is included in the package.json - not sure how much of a difference that makes.
So running a very simple test such as
it('true is true', function(){ expect(true).toEqual(true); });
works fine.
But when I add tests that require the use of an import - eg
import MyService = require('./MyServices');
then when I run the tests it complains as it doesn't know what 'require' is.
Uncaught ReferenceError: require is not defined
Now I'm guessing this is because I need to package up the test module in a similar way that I package up the main project.
So what is the best way to do this?
Should I have multiple entry points in the webpack.config.js file - one for each *.spec.ts file?
Or is there a way to have say accept an unknown number of spec files
entry:[ *.spec.ts ] and have it output a js file for each one - *.spec.js
You can use karma/karma-webpack to run all the tests using webpack for resolving the imports. You can take a look at this repository for a simple configuration.
You can also specify an index.spec.ts as en entry point and make this file require all the spec files if you don't want to make one entry point for each spec.ts in your webpack's configuration file.

WebStorm run all dart unit tests

In WebStorm 11 I want to create a run configuration which runs all dart tests in my project.
However there is no option to do this in the "Dart Test" configuration template. The only options are:
Test Kind: All in file, Test group, single test
Test file: must point to a .dart file, otherwise I get "Dart file is not found"
VM Options (text input)
If I point WebStorm to a single test file this command gets executed in the test window:
C:\path\to\dart\bin\dart.exe --ignore-unrecognized-flags --checked --trace_service_pause_events file:\\\C:\path\to\dart\bin\snapshots\pub.dart.snapshot run test:test -r json C:/path/to/project/test/someclass_test.dart
I don't want to create a run configuration for every unit test class I write, there must be a better way.
Currently I prefer to navigate to the project directory and just run
pub run test:test
This runs all tests which live in files ending with _test.dart which is perfectly what I want. More info here: https://github.com/dart-lang/test#running-tests
Is there no such option in WebStorm for dart developers?
Accordingly to WEB-14747 ticket this functionality is already implemented for the next major version.
You can try latest EAP build of WebStorm v12 here.
I guess that's currently not supported.
The feature to run tests this way is quite new anyway.
If you think this feature is important, lease create a feature request in https://youtrack.jetbrains.com/issues/WEB

Import ember addon code directly from out of the box tests

I'm working on creating an ember addon, and I'm a bit stuck trying to write tests for it. This addon implements a command line option, rather than shipping components etc. As a result, none of the moduleFor type test helpers are relevant for me in the out of the box qunit tests. I'm not rendering any components, I just want a test runner to exersize the implementation behind my command line option.
To write my tests, I'll need to just require my various source files that are up in my addon. For example, files sitting in root/lib. I can't get a require/import that can find these files in a qunit integration test under root/tests/integration. Is this possible? I need a relative path like:
import foo from '../../../lib/foo'
But nothing up there seems to work. The folder structure created for an addon is like:
root
app
lib (was planning on putting my addon impl here)
tests
dummy
helpers
integration
example-test.js (trying to reference code out of the lib folder from here)
It seems like my options in this case are just to fall back to some plain old JS unit testing (qunit, jasmine etc), based up in the root of the addon, not using any ember magic or the dummy app. I would like to stay on the 'out of the box' path provided by ember generate addon, but it seems like I need to go my own way here, so I can reference my source files.
Use
import foo from 'myApp/lib/foo'

Compile unit tests in Adobe CQ5 CRXDE that reference Felix OSGI bundle JUnit code

I want to write some unit tests that run within Adobe CQ 5.4. I am doing what is described in this article for testing within CQ:
http://jtoee.com/2011/09/799/
However, after I create the unit test class in my Java code, it won't compile within CRXDE because it can't resolve the org.junit namespaces. I installed and activated the JUnit bundle in Felix as described (Apache Sling JUnit Core), but I am guessing there is something else I need to do in order for this active Felix bundle to be found in CRXDE. The Felix bundle in the CQ5 instance I am connected to shows these exported packages:
junit.framework,version=4.8.2
org.apache.sling.junit,version=1.0.7.SNAPSHOT
org.apache.sling.junit.annotations,version=1.0.7.SNAPSHOT
org.junit,version=4.8.2
org.junit.matchers,version=4.8.2
org.junit.rules,version=4.8.2
org.junit.runner,version=4.8.2
org.junit.runner.manipulation,version=4.8.2
org.junit.runner.notification,version=4.8.2
org.junit.runners,version=4.8.2
org.junit.runners.model,version=4.8.2
In this sample unit test code below, the last three import statements "cannot be resolved."
import org.apache.sling.api.resource.*;
import org.junit.*;
import org.junit.runner.*;
import org.apache.sling.junit.annotations.*;
#RunWith(SlingAnnotationsTestRunner.class)
public class MyUnitTest {
public ResourceResolver getResourceResolver() {
try {
return getResourceResolverFactory().
getAdministrativeResourceResolver(null);
} catch (LoginException e) {
fail(e.toString());
}
return null;
}
}
It is my novice understanding that the OSGI bundle installed in Felix should be accessible for me to reference in my Java classes using CRXDE, but it isn't happening for the JUnit bundle I installed. Why not? What do I need to do to get CRXDE to find the OSGI bundle reference and compile within CRXDE?
What you're doing looks correct at first sight.
Did you try restarting CQ after installing the required bundles? In theory that should not be required but I'm wondering if the bundle compiler is picking up the newly available packages correctly.
I have uploaded a content package with a similar simple example at http://dl.dropbox.com/u/715349/cq5-examples/junit-tests-1.0.zip (md5 2915123ad581aa225bd531247ea02878), after installing this package on a fresh CQ 5.4 instance the example test is correctly executed via http://localhost:4502/system/sling/junit/
You might want to try my sample and compare with yours.
Short Answer
The problem is not with CQ, the problem is with CRXDE. CRXDE automatically downloads and caches required jar files on your local machine so they don't have to be retrieved constantly from CQ.
If you switch to the 'Package Explore' navigation and then expand the project '{SERVER}{PORT}{HASH}' you should see a folder called Referenced Libraries. Right click and select Build Path >> Configure Build Path. From there you can add any dependencies you want into the project.
Long Answer
CRXDE is not a good tool for creating bundles. It is much better to create bundles through a full fledged IDE such as Eclipse and utilize Apache Maven as a build tool. Apache Maven can automatically manage your dependencies, run tests on your code and separate test vs. runtime dependencies.
That way you can avoid having to load dependencies that you don't really need such a jUnit into your OSGi console and you have more control over how your bundle is built and deployed.
Day has a really nice guide to getting you set up with building CQ projects with Eclipse.
http://dev.day.com/docs/v5_2/html-resources/cq5_guide_developer/ch04s02.html

How to automate module reloading when unit testing with Erlang?

I'm using Emacs and trying to get my unit testing work flow as automated as possible. I have it set up so it is working but I have to manually compile my module under test or the module containing the tests before the Erlang Shell recognizes my changes.
I have two files mymodule.erl and mymodule_tests.erl. What I would like to be able to do is:
Add test case to mymodule_tests
Save mymodule_tests
Switch to the Erlang Shell
Run tests with one line, like eunit:test(mymodule) or mymodule_tests:test()
Have Erlang reload mymodule and mymodule_tests before actually performing the tests
I have tried writing my own test method but it doesn't work.
-module (mytests).
-export([test/0]).
-import(mymodule).
-import(mymodule_tests).
-import(code).
test() ->
code:purge(mymodule),
code:delete(mymodule),
code:load_file(mymodule),
code:purge(mymodule_tests),
code:delete(mymodule_tests),
code:load_file(mymodule_tests),
mymodule_tests:test().
I have also tried by putting -compile(mymodule). into mymodule_tests to see if I could get mymodule to automatically reload when updating mymodule_tests but to no avail.
I have also googled quite a bit but can't find any relevant information. As I'm new to Erlang I'm thinking that I'm either searching for the wrong terms, e.g. erlang reload module, or that you are not supposed to be able reload other modules when compile another module.
Maybe the Erlang make can help you.
make:all([load]).
Reading from the doc:
This function first looks in the
current working directory for a file
named Emakefile (see below) specifying
the set of modules to compile and the
compile options to use. If no such
file is found, the set of modules to
compile defaults to all modules in the
current working directory.
And regarding the "load" option:
Load mode. Loads all recompiled
modules.
There's also a make:files/1,2 which allows you to specify the list of modules to check.
Have you tried using l(mymodule). to reload the module after it's been compiled?