odoo : How to create failed or exeption unit test scenario on odoo? - odoo-8

I created some unit test for odoo modules. Now i need to test exeption case which throw error message UserError for example. I see on log unit test show :
Ran 1 test in 0.284s
FAILED
I want on log :
Ran 1 test in 5.790s
OK
Is it possible to make it on odoo unit test ? and How to create it ?
Thank you

You must use assertRaises
def test_case1(self):
with self.assertRaises(SomeException):
do_something()
https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises

On my case :
with self.assertRaises(Exception) as context:
my_object.button_confirm()
# context.exception[0] is your error message example 'Ups wrong choice'
self.assertTrue('Ups wrong choice' == context.exception[0])

Related

Error Message ( Full Stack Trace ) of Failure Test Is not showing up in Test Result Analyzer - Jenkins

So Basically, I am testing/writing test script to test API in golang. I am using "github.com/stretchr/testify/assert" to assert the expected result to actually result, for ex :
(assert.Equal(t, 200, result, "API is not stable..")
If above assert failed this is what we are seen (( Please check attached screenshot ) in console output of Jenkins.
But , when I check the cause of failure in Test Result Analyzer , I am not seeing full stack trace there.
I am using go-junit-report to generate test report in xml file, and that xml file is read by jenkins through post build action "Publish Junit Test Result Report".
If I use verify through go module :
if result != 200 {
t.Errorf("API is not stable.., got: %d, want; %d.", result, 200)
}
This Stack Trace I can see both the place. Console as well as Test report.

Integrating Cypress with cucumber is failing

I created a simple Cypress project to automate a website and it was working. Now I am trying to convert it into a cucumber Project and when executing the test cases, I am getting below error:
Running: Features/shopping.feature (1 of 1)
[BABEL] Note: The code generator has deoptimised the styling of C:\Users\001ZGA744\Personal\Cypress\Cucumber\node_modules\lodash\lodash.js as it exceeds the max of 500KB.
1) An uncaught error was detected outside of a test
0 passing (941ms)
1 failing
1) An uncaught error was detected outside of a test:
TypeError: The following error originated from your test code, not from Cypress.
> (0 , _typeof4.default) is not a function
When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.
Cypress could not associate this error to any specific test.
We dynamically generated a new test to display this failure.
at _typeof2 (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:303:63)
at _typeof (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:317:39)
at eval (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:23486:2332)
at Object.eval (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:32935:14)
at Object.eval (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:32937:4)
at Object.254.C:\Users\001ZGA744\Personal\Cypress\Cucumber\node_modules\#babel\runtime/helpers/interopRequireDefault (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:32937:17)
at o (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:1:265)
at eval (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:1:316)
at Object.169.babel-runtime/helpers/classCallCheck (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:9432:15)
at o (http://localhost:60964/__cypress/tests?p=cypress\integration\Features\shopping.feature:1:265)
This is how my Project Structure looks like:
I am unable to understand the reason of the issue.
Please suggest.
Please remember you need a stepDefinitions folder at least. And then, in the package.json file you should declare the Cypress Cucumber Preprocessor Style pattern.
Something like this:
"cypress-cucumber-preprocessor": {
"nonGlobalStepDefinitions": true
}
Or:
"cypress-cucumber-preprocessor": {
"commonPath": "common",
"stepDefinitions": "step_definitions"
}
Depending on what you choose.

Failed test in protractor stops the execution for rest test cases

I am running the protractor Suite (spec file having multiple test cases), If any test case fails, protractor does not continue with the next test case execution and all the rest of test cases also fail.
EXPECTED BEHAVIOR:
Upon failure on any test case, protractor should continue with next test case execution.
I used "Protractor-Fail-Fast" Npm package to stop the rest test case execution if any test case fail. But ideally I am not looking for the same.
But this will not help me!
Just for reference: In Visual Studio MS test, If I created ordered test (same as Spec file in protractor having multiple test cases) and then set test setting like "continue on failure", ordered test execution will continue even if some test case failed.
I am looking for a similar test setting or any solution for protractor.
If you dont't want to stop all tests run just stop using Protractor-Fail-Fast library? Protractor tests run till the end by default even if some of the tests are failed.
set ignoreUncaughtExceptions: true in config file as following:
/**
* If set, Protractor will ignore uncaught exceptions instead of exiting
* without an error code. The exceptions will still be logged as warnings.
*/
ignoreUncaughtExceptions?: boolean;
you can get above description from here
export.config = {
...
ignoreUncaughtExceptions: true
}

Single quote in double quote test name of Spock test leads to 'unexpected token', BUT only when run with gradle and as isolated test

I just installed intellij and downloaded the geb-example-grade (https://github.com/geb/geb-example-gradle). In Intellij settings I configured under gradle/runner: Run test using: Let me choose per test. Then I ran the test "can get to the current Book of Geb" with gradle and it worked fine also running the GebishOrgSpec class worked fine. Then I added a single quote to the methodname of the test, i.e. "can ' get to the current Book of Geb". Running the GebishOrgSpec class (containing that test) with gradle still works fine. But when I run the test with gradle (i.e. after Alt-Shift-F10 in the run menu I choose "GebishOrgSpec.can ' get to the current Book of Geb" instaead of "GebishOrgSpec") i get the following error:
FAILURE: Build failed with an exception.
* Where:
Initialization script '/tmp/ijtestinit3.gradle' line: 6
* What went wrong:
Could not compile initialization script '/tmp/ijtestinit3.gradle'.
> startup failed:
initialization script '/tmp/ijtestinit3.gradle': 6: unexpected token: get # line 6, column 49.
ludes = ['GebishOrgSpec.can ' get to the
^
1 error
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
Cause: startup failed:
initialization script '/tmp/ijtestinit3.gradle': 6: unexpected token: get # line 6, column 49.
ludes = ['GebishOrgSpec.can ' get to the
^
1 error
I also tried run running the test with Junit (after setting the driver path) that also works fine. For me it makes absolutely no sense that the very same test works when running the class but not when running the method of the class. Here just to be complete also the class code:
import geb.spock.GebSpec
class GebishOrgSpec extends GebSpec {
def "can ' get to the current Book of Geb"() {
when:
to GebishOrgHomePage
and:
manualsMenu.open()
then:
manualsMenu.links[0].text().startsWith("current")
when:
manualsMenu.links[0].click()
then:
at TheBookOfGebPage
}
}
Update: I had this behaviour on two different computers, but i would appreciate if others also test this. It should be fairly easy to reproduce (if there are questions on the description above, let me know.) Maybe u won't have the error and i have some bad configurations or u can confirm this bug and we raise the attention for it.

How do I resolve oracle jdbc proxy class error in Evosuite generated tests?

I've written a JDBC driver and I'm trying to use Evosuite to generate the tests for it.
I'm using the following command line:
mvn -Dcores=5 -DmemoryInMB=5000 -Dmock_if_no_generator=false -DextraArgs=' -Dmock_if_no_generator=false -Dskip_covered=true Duse_separate_classloader=false -Dmax_recursion=50 -Dlocal_search_restore_coverage=true -Duse_existing_coverage=true -Dsandbox=false -Dsort_calls=true 'evosuite:generate
The code that is generated is below:
oracle.1jdbc.1replay.1driver.1NonTxnReplayableBase.2java.1sql.1DatabaseMetaData...Proxy oracle_1jdbc_1replay_1driver_1NonTxnReplayableBase_2java_1sql_1DatabaseMetaData___Proxy0 = new oracle.1jdbc.1replay.1driver.1NonTxnReplayableBase.2java.1sql.1DatabaseMetaData...Proxy((DatabaseMetaData) null, "k-{`1N&KKC", proxyFactory0, hashtable0);
and I'm getting the following error on the first line:
:[4618,7] not a statement
:[4618,13] ';' expected
(getting this error three times on the same line)
I was hoping to turn off the mocking but it didn't work it seems.
I'll try to see if I can provide more details later, but any initial thoughts from anyone?
Thanks!

Resources