pip install coverage
coverage run manage.py test
coverage report
coverage html
python -m http.serverpip install mommy
python manage.py shell
from model_mommy import mommy
cargo = mommy.make('Cargo')
cargos = mommy.make('Cargo', _quantity=5)| test('ReverseInt function exists', () => { | |
| expect(reverseInt).toBeDefined(); //funcao existe | |
| expect(typeof steps).toEqual('function'); // é funcao | |
| expect(typeof Queue.prototype.constructor).toEqual('function'); // Class | |
| expect(reverseInt(0)).toEqual(0); | |
| expect(palindrome('aba')).toBeTruthy(); | |
| expect(palindrome(' aba')).toBeFalsy(); | |
| }); | |
| test('can remove elements from a queue', () => { | |
| const q = new Queue(); | |
| expect(() => { | |
| q.add(1); | |
| q.remove(); | |
| }).not.toThrow(); | |
| }); | |
| // console.log | |
| test('Calling fizzbuzz with 15 prints out the correct values', () => { | |
| fizzBuzz(15); | |
| expect(console.log.mock.calls[0][0]).toEqual(1); | |
| expect(console.log.mock.calls[1][0]).toEqual(2); | |
| expect(console.log.mock.calls[2][0]).toEqual('fizz'); | |
| expect(console.log.mock.calls[3][0]).toEqual(4); | |
| expect(console.log.mock.calls[4][0]).toEqual('buzz'); | |
| expect(console.log.mock.calls[5][0]).toEqual('fizz'); | |
| expect(console.log.mock.calls[6][0]).toEqual(7); | |
| expect(console.log.mock.calls[7][0]).toEqual(8); | |
| expect(console.log.mock.calls[8][0]).toEqual('fizz'); | |
| expect(console.log.mock.calls[9][0]).toEqual('buzz'); | |
| expect(console.log.mock.calls[10][0]).toEqual(11); | |
| expect(console.log.mock.calls[11][0]).toEqual('fizz'); | |
| expect(console.log.mock.calls[12][0]).toEqual(13); | |
| expect(console.log.mock.calls[13][0]).toEqual(14); | |
| expect(console.log.mock.calls[14][0]).toEqual('fizzbuzz'); | |
| }); | |
| beforeEach(() => { | |
| jest.spyOn(console, 'log'); | |
| }); | |
| afterEach(() => { | |
| console.log.mockRestore(); | |
| }); | |
| { | |
| "name": "dev", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "scripts": { | |
| "test": "echo \"Error: no test specified\" && exit 1" | |
| }, | |
| "jest": { | |
| "testEnvironment": "node" | |
| }, | |
| "author": "", | |
| "license": "ISC", | |
| "dependencies": {} | |
| } |
| from utils import money | |
| from django.test import TestCase | |
| def add_num(num): | |
| return num | |
| class SimplesTestCase(TestCase): | |
| def setUp(self): | |
| self.numero = 42 | |
| def test_add_num(self): | |
| valor = add_num(self.numero) | |
| self.assertTrue(valor == 42) | |
| class UtilsMoneyTest(TestCase): | |
| def setUp(self): | |
| self.numero = 42 | |
| self.carrinho = { | |
| 1: {'quantidade': 5, 'preco_quantitativo_promocional': 10, 'preco_quntitativo': 7}, | |
| 2: {'quantidade': 5, 'preco_quantitativo_promocional': 10}, | |
| 5: {'quantidade': 5, 'preco_quantitativo_promocional': 10} | |
| } | |
| def test_formata_preco(self): | |
| valor = money.formata_preco(self.numero) | |
| self.assertTrue(valor == "R$ 42,00") | |
| def test_cart_total_qtd(self): | |
| valor = money.cart_total_qtd(self.carrinho) | |
| self.assertTrue(valor == 15) | |
| def test_cart_totls(self): | |
| valor = money.cart_totals(self.carrinho) | |
| self.assertTrue(valor == 30) |