unit testing - How to test binders/property editors used on spring 2.5 controllers

I have an annotated controller with a method that expects a model and a binding result@RequestMapping(method = RequestMethod.POST) public ModelAndView submit(@ModelAttribute(“user”) User user, BindingResult bindingResult) { //do something}How do I test the binding result? If I call the method with a user and a binding result then I'm not testing the binding process. I figure there myst be something that takes a MockHttpServletRequest and returns the model and the binding result, any suggestions?...Read more

unit testing - Breaking dependencies when you can't make changes to other files?

I'm doing some stealth agile development on a project. The lead programmer sees unit testing, refactoring, etc as a waste of resources and there is no way to convince him otherwise. His philosophy is "If it ain't broke don't fix it" and I understand his point of view. He's been working on the project for over a decade and knows the code inside and out. I'm not looking to debate development practices.I'm new to the project and I've been tasked with adding a new feature. I've worked on legacy projects before and used agile development practices w...Read more

unit testing - How to mock pg-promise library with jest

I am trying to mock the pg promise library. I want to be able mock return whether the promise rejects or resolves. Here is an example function and test: const pgp = require('pg-promise')({});const someFunc = callback => { const db = pgp('connectionString'); db .none('create database test;') .then(() => { callback(null, 'success'); }) .catch(err => { callback(err); });};module.exports = { someFunc};And i wanna test it like so:const { someFunc } = require('./temp');let pgp = require('pg-promise')({ noLocking:...Read more

reactjs - Having trouble Jest testing ajax modules with axios

I have a module called ajax.js that exports a bunch of ajax functions for me. I'm trying to test the following function with Jest:export const status = ({loginUrl='/', logoutUrl='/'}) => { return axios.get(`/auth?login=${loginUrl}&logout=${logoutUrl}`);};My test looks like this:jest.unmock('../ajax');import { status } from '../ajax';describe('ajax', () => { let urls; beforeEach(() => { urls = { loginUrl: '/', logoutUrl: '/' }; }); it('calls status with a login and logout url', () => { const { loginUrl, lo...Read more

unit testing - Test Action of Redux-thunk use JEST

I want to write a test for Axios use Jest Framework. I'm using Redux. Here is my function get-request of Axiosexport const getRequest = a => dispatch => { return axios .get(a) .then(function(response) { dispatch({ type: FETCH_DATA, payload: response.data }); }) .catch(function(error) { dispatch({ type: ERROR_DATA, payload: { status: error.response.status, statusText: error.response.statusText } }); });};thanks in advance :)...Read more

unit testing - How to fix error import Vue from 'vue' results in SyntaxError: Unexpected identifier

I'm trying to setup a test framework for a Vue.js project that I'm working on. I'm trying to use Jest for this but I end up with an error I don't seem to find a solution for. When I'm trying to run the tests, I get a syntax error in the terminal.The error I'm getting is:Test suite failed to runImport Vue from 'vue'; ^^^SyntaxError: Unexpected identifier" at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17) I've been looking around but I can't find a solution that helps me..When remo...Read more

unit testing - Why does VSTestHost.exe load assembly from c:\windows\assembly\temp directory?

I am developing an assembly which has to be installed in the GAC, and as part of a post-build step I ensure that the GAC gets updated after each build. If I create a (Visual Studio) unit test (in a seperate tests assembly) to call a new method on a class under test, then implement the method on the class under test (TDD style), then run the test (CTRL R, T) the assembly under test and the unit test project get built (and the assembly is updated in the GAC). The test fails (throws a System.MissingMethodException for the new method). If I now deb...Read more

security - .NET Core 2.0 User Secrets and Unit Testing

I'm currently working on a .net core solution (multiple projects) that uses Microsoft's app secrets management. I can pull secrets back in my runtime project (e.g. Console app), but when it comes to leveraging user secrets for integration tests in a separate project (e.g. Model.Test project), what's the right approach? I can think of a few options:Give each project the same UserSecretsId: This seems like it'd made sense for test projects that may leverage the same secrets that the runtime project uses.Let each project have unique UserSecretsId:...Read more

unit testing - how to create a mock in a model test case

Maybe I am doing this wrong.I'd like to test the beforeSave method of a model (Antibody). A part of this method calls a method on an associated model (Species). I'd like to mock the Species model but don't find how. Is it possible or am I doing something that goes against the MVC pattern and thus trying to do something that I shouldn't?class Antibody extends AppModel { public function beforeSave() { // some processing ... // retreive species_id based on the input $this->data['Antibody']['species_id'] = is...Read more