Nodejs : Wordbucket GitHub Link
Commit 13 Nodejs Wordbucket : first functional test and unit test try
Commits on May 2, 2018
Link GitHub Commit 13 Wordbucket Nodejsทำการลบ functional test อันเก่าของเพื่อนออก(import และตั้งค่าในหลายๆส่วนผิด) เพื่อไม่เป็นการเสียเวลาจึงลบออกและลงอันที่ผมทำไว้ทดสอบก่อนหน้าแทน
| @@ -1,35 +0,0 @@ | ||
| -from selenium import webdriver | ||
| -from selenium.webdriver.common.keys import Keys | ||
| -import time | ||
| -import unittest | ||
| - | ||
| - | ||
| -class NewVisitorTest(webdriver): | ||
| - | ||
| - def setUp(self): | ||
| - self.browser = webdriver.Firefox() | ||
| - browser.get('http://localhost:3000') | ||
| - | ||
| - def tearDown(self): | ||
| - self.browser.quit() | ||
| - | ||
| - def test_can_start_a_list_and_retrieve_it_later(self): | ||
| - | ||
| - | ||
| - # Ann has heard about a cool new online word app. She goes | ||
| - # to check out its homepage | ||
| - self.browser.get(self.live_server_url) | ||
| - | ||
| - # She notices the page title and header mention Word Bucket lists | ||
| - self.assertIn(' WordBucket ', self.browser.title) | ||
| - header_text = self.browser.find_element_by_tag_name('h1').text | ||
| - self.assertIn(' A Simple WordBucket App ', header_text) | ||
| - | ||
| - | ||
| - | ||
| - | ||
| - | ||
| - self.fail('Finish the test!') | ||
| - | ||
| -if __name__ == '__main__': | ||
| - unittest.main(warnings='ignore') |
functional_test.py
- ต้องเปิด server ก่อน run test ใน commit นี้มีแค่เพียง test เดียวง่ายๆเป็น site ของเรา และ assert title
| @@ -0,0 +1,23 @@ | ||
| +from selenium import webdriver | ||
| +import unittest | ||
| + | ||
| +class NewVisitorTest(unittest.TestCase): | ||
| + | ||
| + def setUp(self): | ||
| + self.browser = webdriver.Firefox() | ||
| + | ||
| + def tearDown(self): | ||
| + self.browser.quit() | ||
| + | ||
| + def test_can_start_a_list_and_retrieve_it_later(self): | ||
| + # Edith has heard about a cool new online to-do app. She goes | ||
| + # to check out its homepage | ||
| + self.browser.get('http://localhost:3000') | ||
| + | ||
| + # She notices the page title and header mention to-do lists | ||
| + self.assertIn('WordBucket App', self.browser.title) | ||
| + | ||
| + # She is invited to enter a to-do item straight away | ||
| + | ||
| +if __name__ == '__main__': | ||
| + unittest.main(warnings='ignore') |
test/test.js
- ใช้ mocha chai supertest test status function ต่างๆตามความเหมาะสม ในการทดสอบขั้นต้น
114 test/test.js
| @@ -0,0 +1,114 @@ | ||
| +//During the test the env variable is set to test | ||
| +process.env.NODE_ENV = 'test'; | ||
| + | ||
| +var db = require('../models'); | ||
| +var Word = db.Word; | ||
| +var Explanation = db.Explanation; | ||
| +var chai = require('chai'); | ||
| +var expect = require('chai').expect; | ||
| +var superagent = require('superagent'); | ||
| +var supertest = require('supertest'); | ||
| +var index = require('../index.js'); | ||
| +var should = chai.should(); | ||
| +var request = require('request'); | ||
| + | ||
| +var server = supertest.agent("http://localhost:3000/"); | ||
| + | ||
| +describe('Unit testing', function(){ | ||
| + | ||
| + //------------HomePageTest------------// | ||
| + it('test_uses_home_template', function(done){ | ||
| + server | ||
| + .get("") | ||
| + .expect(200) | ||
| + .end(function(err, res){ | ||
| + res.status.should.equal(200); | ||
| + done(); | ||
| + }); | ||
| + }); | ||
| + | ||
| + //------------NewWordTest------------// | ||
| + it('test_redirect_after_add_word', function(done){ | ||
| + server | ||
| + .post("addword") | ||
| + .send({word_input: "JA",explanation_input: "VA"}) | ||
| + .expect("Content-type",/json/) | ||
| + .expect(302) | ||
| + .end(function(err, res){ | ||
| + res.status.should.equal(302); | ||
| + done(); | ||
| + }); | ||
| + }); | ||
| + | ||
| + it('test_save_POST_after_add_word', function(done){ | ||
| + server | ||
| + .post("addword") | ||
| + .send({word_input: "JA",explanation_input: "VA"}) | ||
| + .expect("Content-type",/json/) | ||
| + .expect(302) | ||
| + .end(function(err, res){ | ||
| + res.status.should.equal(302); | ||
| + | ||
| + Word.create({ | ||
| + word: "TEST", | ||
| + }).then( function (test) { | ||
| + // do some tests on article here | ||
| + test.destroy(); | ||
| + done(); | ||
| + }); | ||
| + }); | ||
| + }); | ||
| + | ||
| +/* | ||
| + //------------AllAroundModelsTest------------// | ||
| + it('test_saving_and_retrieving_words', function(){ | ||
| + chai.request(server) | ||
| + .get('/') | ||
| + .end(function(err, res){ | ||
| + res.status.should.equal(200); | ||
| + res.should.be.json; | ||
| + res.body.should.be.a('array'); | ||
| + done(); | ||
| + }); | ||
| + }); | ||
| + | ||
| +/* | ||
| + //------------NewWordTest------------// | ||
| + it('test_can_save_a_POST_request', function(){ | ||
| + | ||
| + }); | ||
| + | ||
| + //------------NewExplanationTest------------// | ||
| + it('test_can_save_a_POST_request_to_an_existing_word', function(){ | ||
| + | ||
| + }); | ||
| + it('test_redirects_to_word_view', function(){ | ||
| + | ||
| + }); | ||
| + | ||
| + | ||
| +/* ================== future test ================== | ||
| + | ||
| + //------------SearchAndBrowseTest------------// | ||
| + it('test_uses_search_template', function(){ | ||
| + | ||
| + }); | ||
| + it('test_render_after_POST', function(){ | ||
| + | ||
| + }); | ||
| + it('test_return_correct_text', function(){ | ||
| + | ||
| + }); | ||
| + | ||
| + //------------VoteTest------------// | ||
| + it('test_redirects_like_to_word_view', function(){ | ||
| + | ||
| + }); | ||
| + it('test_redirects_dislike_to_word_view', function(){ | ||
| + | ||
| + }); | ||
| + | ||
| + | ||
| +*/ | ||
| + | ||
| +}); |
ไม่มีความคิดเห็น:
แสดงความคิดเห็น